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 ⇒ 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) ⇒ Object
Allows us to have a nice DSL for defining schedules.
Constructor Details
#initialize(version:) ⇒ Schedule
Returns a new instance of Schedule.
47 48 49 50 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 47 def initialize(version:) @version = version @tasks = {} end |
Instance Attribute Details
#tasks ⇒ Hash{String => Task} (readonly)
42 43 44 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 42 def tasks @tasks end |
#version ⇒ String (readonly)
39 40 41 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 39 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
55 56 57 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 55 def <<(task) @tasks[task.id] = task end |
#each ⇒ Object
Iterates over tasks yielding them one after another
60 61 62 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 60 def each(&) @tasks.each_value(&) end |
#find(id) ⇒ Task?
Returns task with a given id or nil if not found.
66 67 68 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 66 def find(id) @tasks[id] end |