Class: Zizq::CrontabEntry
- Inherits:
-
Object
- Object
- Zizq::CrontabEntry
- Defined in:
- lib/zizq/crontab_entry.rb
Overview
Represents a single entry within a Crontab schedule.
Each entry specifies the cron expression at which it executes, information about when it last/next enqueued a job, and details of the job that the entry enqueues.
Entries can be paused or resumed, and can be deleted or redefined in place.
Instance Attribute Summary collapse
-
#crontab ⇒ Object
readonly
The Crontab schedule to which this entry belongs.
-
#expression ⇒ Object
readonly
The cron expression used to define the schedule for the entry.
-
#job ⇒ Object
readonly
Parameters that will be used to enqueue jobs each time the schedule fires.
-
#last_enqueue_at ⇒ Object
readonly
The timestamp at which a job was last enqueued for this entry.
-
#name ⇒ Object
readonly
The name of this entry within the schedule.
-
#next_enqueue_at ⇒ Object
readonly
The timestamp at which the next job will be enqueued for this entry.
-
#paused ⇒ Object
readonly
True if this entry is currrently paused.
-
#paused_at ⇒ Object
readonly
The timestamp at which this entry was last paused.
-
#resumed_at ⇒ Object
readonly
The timestamp at which this entry was last resumed.
-
#timezone ⇒ Object
readonly
The timezone in which the schedule entry is processed.
Instance Method Summary collapse
-
#delete! ⇒ Object
Delete the entry from the schedule.
-
#initialize(crontab, name, expression, job:, timezone: nil, paused: nil, paused_at: nil, resumed_at: nil, last_enqueue_at: nil, next_enqueue_at: nil) ⇒ CrontabEntry
constructor
Initialize the entry with all configured parameters.
-
#pause! ⇒ Object
Pause the entry within the schedule.
-
#redefine(expression, timezone: nil, paused: nil) ⇒ Object
Replace this entry with another.
-
#resume! ⇒ Object
Resume this entry if it is currently paused.
- #to_params ⇒ Object
Constructor Details
#initialize(crontab, name, expression, job:, timezone: nil, paused: nil, paused_at: nil, resumed_at: nil, last_enqueue_at: nil, next_enqueue_at: nil) ⇒ CrontabEntry
Initialize the entry with all configured parameters.
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/zizq/crontab_entry.rb', line 65 def initialize(crontab, name, expression, job:, timezone: nil, paused: nil, paused_at: nil, resumed_at: nil, last_enqueue_at: nil, next_enqueue_at: nil) @crontab = crontab @name = name @expression = expression @timezone = timezone @job = job @paused = paused @paused_at = paused_at @resumed_at = resumed_at @last_enqueue_at = last_enqueue_at @next_enqueue_at = next_enqueue_at end |
Instance Attribute Details
#crontab ⇒ Object (readonly)
The Crontab schedule to which this entry belongs.
17 18 19 |
# File 'lib/zizq/crontab_entry.rb', line 17 def crontab @crontab end |
#expression ⇒ Object (readonly)
The cron expression used to define the schedule for the entry.
Both standard 5-field and enhanced 6-field cron (with seconds) are supported, along with @daily, @weekly etc.
26 27 28 |
# File 'lib/zizq/crontab_entry.rb', line 26 def expression @expression end |
#job ⇒ Object (readonly)
Parameters that will be used to enqueue jobs each time the schedule fires.
These are the same parameters as those used to enqueue jobs normally.
36 37 38 |
# File 'lib/zizq/crontab_entry.rb', line 36 def job @job end |
#last_enqueue_at ⇒ Object (readonly)
The timestamp at which a job was last enqueued for this entry.
48 49 50 |
# File 'lib/zizq/crontab_entry.rb', line 48 def last_enqueue_at @last_enqueue_at end |
#name ⇒ Object (readonly)
The name of this entry within the schedule.
20 21 22 |
# File 'lib/zizq/crontab_entry.rb', line 20 def name @name end |
#next_enqueue_at ⇒ Object (readonly)
The timestamp at which the next job will be enqueued for this entry.
51 52 53 |
# File 'lib/zizq/crontab_entry.rb', line 51 def next_enqueue_at @next_enqueue_at end |
#paused ⇒ Object (readonly)
True if this entry is currrently paused.
39 40 41 |
# File 'lib/zizq/crontab_entry.rb', line 39 def paused @paused end |
#paused_at ⇒ Object (readonly)
The timestamp at which this entry was last paused.
42 43 44 |
# File 'lib/zizq/crontab_entry.rb', line 42 def paused_at @paused_at end |
#resumed_at ⇒ Object (readonly)
The timestamp at which this entry was last resumed.
45 46 47 |
# File 'lib/zizq/crontab_entry.rb', line 45 def resumed_at @resumed_at end |
#timezone ⇒ Object (readonly)
The timezone in which the schedule entry is processed.
Defaults to the Zizq server timezone unless specified.
31 32 33 |
# File 'lib/zizq/crontab_entry.rb', line 31 def timezone @timezone end |
Instance Method Details
#delete! ⇒ Object
Delete the entry from the schedule.
111 112 113 114 |
# File 'lib/zizq/crontab_entry.rb', line 111 def delete! #: () -> void Zizq.client.delete_cron_group_entry(crontab.name, name) crontab.entries.delete(name) end |
#pause! ⇒ Object
Pause the entry within the schedule.
This is independent of the paused state of the Crontab itself.
119 120 121 122 123 124 125 126 127 |
# File 'lib/zizq/crontab_entry.rb', line 119 def pause! #: () -> void materialize_with( Zizq.client.update_cron_group_entry( crontab.name, name, paused: true, ), ) end |
#redefine(expression, timezone: nil, paused: nil) ⇒ Object
Replace this entry with another.
This is equivalent to calling ‘crontab.define_entry` with the same name.
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/zizq/crontab_entry.rb', line 95 def redefine(expression, timezone: nil, paused: nil) CrontabEntryBuilder.new(crontab, name, expression, timezone:, paused:) do |e| materialize_with( Zizq.client.replace_cron_group_entry( crontab.name, name, expression: e.expression, job: e.job.to_enqueue_params, timezone: e.timezone, paused: e.paused, ), ) end end |
#resume! ⇒ Object
Resume this entry if it is currently paused.
If the parent Crontab itself is paused, the entry will still not enqueue jobs until the Crontab is resumed.
133 134 135 136 137 138 139 140 141 |
# File 'lib/zizq/crontab_entry.rb', line 133 def resume! #: () -> void materialize_with( Zizq.client.update_cron_group_entry( crontab.name, name, paused: false, ), ) end |
#to_params ⇒ Object
145 146 147 148 149 150 151 152 153 |
# File 'lib/zizq/crontab_entry.rb', line 145 def to_params { name:, expression:, timezone:, job: job.to_enqueue_params, paused:, }.compact #: Zizq::cron_entry_params end |