This repository has been archived on 2023-06-05. You can view files and clone it, but cannot push or open issues or pull requests.
service/examples/example.cr

43 lines
740 B
Crystal

require "../src/service"
require "log"
class MessageService < Service
Log = ::Log.for(self)
@@i = 0
getter message
getter delay
getter times
def initialize(@message : String, @delay : Int32, @times : Int32)
end
def run(_unit : Unit) : Service::Unit?
puts @message
@@i += 1
Log.info { @@i }
sleep @delay
if @@i < @times
Service::Unit.new(self)
else
Log.info { "Done." }
nil
end
end
end
class Runner < Service::Runner
def starters : Array(Service::Starter)
[
Service::AsynchronousStarter.new([
MessageService.new("Hello world from AsynchronousStarter!", delay: 1, times: 5).as(Service),
]).as(Service::Starter),
]
end
end
Runner.new.run