Class: Nanobot::Scheduler::SchedulerService

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(store:, bus:, logger: nil, tick_interval: TICK_INTERVAL) ⇒ SchedulerService

Returns a new instance of SchedulerService.

Parameters:

  • store (ScheduleStore) —

    schedule persistence layer

  • bus (Bus::MessageBus) —

    message bus for publishing inbound messages

  • logger (Logger, nil) (defaults to: nil) —

    optional logger

  • tick_interval (Numeric) (defaults to: TICK_INTERVAL) —

    seconds between schedule evaluation ticks



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

Returns:

  • (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