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.
39 40 41 42 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 39 def initialize(version:) @version = version @tasks = {} end |
Instance Attribute Details
#tasks ⇒ Hash{String => Task} (readonly)
34 35 36 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 34 def tasks @tasks end |
#version ⇒ String (readonly)
31 32 33 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 31 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
47 48 49 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 47 def <<(task) @tasks[task.id] = task end |
#each ⇒ Object
Iterates over tasks yielding them one after another
52 53 54 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 52 def each(&) @tasks.each_value(&) end |
#find(id) ⇒ Task?
Returns task with a given id or nil if not found.
58 59 60 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 58 def find(id) @tasks[id] end |
#schedule(**args) ⇒ Object
Allows us to have a nice DSL for defining schedules
67 68 69 |
# File 'lib/karafka/pro/recurring_tasks/schedule.rb', line 67 def schedule(**args, &) self << Task.new(**args, &) end |