Class: Karafka::Pro::RecurringTasks::Schedule
- Inherits:
-
Object
- Object
- Karafka::Pro::RecurringTasks::Schedule
- Defined in:
- lib/karafka/pro/recurring_tasks/schedule.rb
Overview
Represents the current code-context schedule with defined tasks and their cron execution details. Single schedule includes all the information about all the tasks that we have defined and to be executed in a given moment in time.
Instance Attribute Summary collapse
- #tasks ⇒ Hash<String, Task> readonly
- #version ⇒ String readonly
Instance Method Summary collapse
-
#<<(task) ⇒ Object
Adds task into the tasks accumulator.
-
#each(&block) ⇒ Object
Iterates over tasks yielding them one after another.
-
#find(id) ⇒ Task?
Task with a given id or nil if not found.
-
#initialize(version:) ⇒ Schedule
constructor
A new instance of Schedule.
-
#schedule(**args, &block) ⇒ Object
Allows us to have a nice DSL for defining schedules.
Constructor Details
#initialize(version:) ⇒ Schedule
Returns a new instance of Schedule.
30 31 32 33 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 30 def initialize(version:) @version = version @tasks = {} end |
Instance Attribute Details
#tasks ⇒ Hash<String, Task> (readonly)
25 26 27 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 25 def tasks @tasks end |
#version ⇒ String (readonly)
22 23 24 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 22 def version @version end |
Instance Method Details
#<<(task) ⇒ Object
Note:
In case of multiple tasks with the same id, it will overwrite
Adds task into the tasks accumulator
38 39 40 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 38 def <<(task) @tasks[task.id] = task end |
#each(&block) ⇒ Object
Iterates over tasks yielding them one after another
44 45 46 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 44 def each(&block) @tasks.each_value(&block) end |
#find(id) ⇒ Task?
Returns task with a given id or nil if not found.
50 51 52 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 50 def find(id) @tasks[id] end |