Module: OMQ::Engine::Maintenance

Defined in:
lib/omq/engine/maintenance.rb

Overview

Spawns a periodic maintenance task for the parent mechanism.

The mechanism declares maintenance needs via #maintenance, which returns { interval:, task: } or nil.

Class Method Summary collapse

Class Method Details

.start(parent_task, mechanism, tasks) ⇒ Object

Parameters:

  • parent_task (Async::Task)
  • mechanism (#maintenance, nil)
  • tasks (Array<Async::Task>)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/omq/engine/maintenance.rb', line 17

def self.start(parent_task, mechanism, tasks)
  return unless mechanism.respond_to?(:maintenance)
  spec = mechanism.maintenance
  return unless spec

  interval = spec[:interval]
  callable = spec[:task]

  tasks << parent_task.async(transient: true, annotation: "mechanism maintenance") do
    Async::Loop.quantized(interval: interval) do
      callable.call
    end
  rescue Async::Stop
    # clean shutdown
  end
end