Class: Nanobot::Scheduler::SchedulerService
- Inherits:
-
Object
- Object
- Nanobot::Scheduler::SchedulerService
- Defined in:
- lib/nanobot/scheduler/service.rb
Overview
SchedulerService runs a background thread that evaluates schedules and publishes InboundMessages to the bus when jobs are due
Constant Summary collapse
- TICK_INTERVAL =
15
Instance Method Summary collapse
-
#initialize(store:, bus:, logger: nil, tick_interval: TICK_INTERVAL) ⇒ SchedulerService
constructor
A new instance of SchedulerService.
- #running? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(store:, bus:, logger: nil, tick_interval: TICK_INTERVAL) ⇒ SchedulerService
Returns a new instance of SchedulerService.
17 18 19 20 21 22 23 24 |
# File 'lib/nanobot/scheduler/service.rb', line 17 def initialize(store:, bus:, logger: nil, tick_interval: TICK_INTERVAL) @store = store @bus = bus @logger = logger || Logger.new(IO::NULL) @tick_interval = tick_interval @running = false @thread = nil end |
Instance Method Details
#running? ⇒ Boolean
39 40 41 |
# File 'lib/nanobot/scheduler/service.rb', line 39 def running? @running end |
#start ⇒ Object
26 27 28 29 30 31 |
# File 'lib/nanobot/scheduler/service.rb', line 26 def start @running = true setup_response_routing @thread = Thread.new { run_loop } @logger.info "Scheduler service started (tick: #{@tick_interval}s)" end |
#stop ⇒ Object
33 34 35 36 37 |
# File 'lib/nanobot/scheduler/service.rb', line 33 def stop @running = false @thread&.join(5) @logger.info 'Scheduler service stopped' end |