Class: NulogyMessageBusConsumer::Steps::TimedTask
- Inherits:
-
Object
- Object
- NulogyMessageBusConsumer::Steps::TimedTask
- Defined in:
- lib/nulogy_message_bus_consumer/steps/timed_task.rb
Overview
A generic class to run a “task” on a timer (in a separate thread!) This class runs the code, the Task does the work
A Task must implement the methods called in this class:
-
#extract_args(kwargs) Called with the keyword arguments (kwargs) that is passed to this step. This is a chance to pull out references to pipeline variables (e.g. kafka_consumer)
-
#call The work the Task should perform
-
#interval The time, in seconds, between invocations of #call
Instance Method Summary collapse
- #call(**kwargs) ⇒ Object
-
#initialize(task) ⇒ TimedTask
constructor
A new instance of TimedTask.
Constructor Details
#initialize(task) ⇒ TimedTask
Returns a new instance of TimedTask.
15 16 17 |
# File 'lib/nulogy_message_bus_consumer/steps/timed_task.rb', line 15 def initialize(task) @task = task end |
Instance Method Details
#call(**kwargs) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/nulogy_message_bus_consumer/steps/timed_task.rb', line 19 def call(**kwargs) @task.extract_args(**kwargs) # Ensure that the process is terminated if there is a problem getting the consumption lag. # This also ensures that the process will terminate on-boot if it cannot connect to Kafka, # allowing the container to be terminated by ECS. Thread.abort_on_exception = true Thread.new { run } yield end |