Class: Zizq::CrontabEntryBuilder
- Inherits:
-
Object
- Object
- Zizq::CrontabEntryBuilder
- Defined in:
- lib/zizq/crontab_entry_builder.rb,
sig/generated/zizq/crontab_entry_builder.rbs
Overview
Builder class used to define individual entries within a Crontab schedule.
This is used internally by Zizq.define_crontab. See documentation for
that method for full details.
Callers must call one of the enqueue methods to complete the build process.
Instance Attribute Summary collapse
-
#callback ⇒ ^(Zizq::CrontabEntry) -> Zizq::CrontabEntry
readonly
Callback through which the built entry is passed before being added to the Crontab schedule.
-
#expression ⇒ String
readonly
The cron expression for the entry.
-
#name ⇒ String
readonly
The name of the entry being built.
-
#paused ⇒ Boolean?
readonly
True if this entry will be paused.
-
#target ⇒ Zizq::Crontab
readonly
The Crontab instance onto which entries are applied.
-
#timezone ⇒ String?
readonly
Optional timezone for the entry.
Instance Method Summary collapse
-
#enqueue(job_class, *args, **kwargs, &block) ⇒ void
Enqueue a Zizq::Job or ActiveJob class using Zizq::ActiveJobConfig via this entry.
-
#enqueue_bulk {|arg0| ... } ⇒ self
Bulk enqueues are not supported via cron.
-
#enqueue_raw(queue:, type:, payload:, **opts) ⇒ void
Process a raw job enqueue for this entry.
-
#enqueue_with(**overrides) ⇒ EnqueueWith
Provide common fields to be used when enqueueing a job.
-
#initialize(target, name, expression, timezone: nil, paused: nil, &block) ⇒ CrontabEntryBuilder
constructor
Initialize the builder with the given inputs.
- #push_entry(req) ⇒ Object
Constructor Details
#initialize(target, name, expression, timezone: nil, paused: nil, &block) ⇒ CrontabEntryBuilder
Initialize the builder with the given inputs.
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/zizq/crontab_entry_builder.rb', line 49 def initialize(target, name, expression, timezone: nil, paused: nil, &block) @target = target @name = name @expression = expression @timezone = timezone @paused = paused @callback = block || :itself.to_proc end |
Instance Attribute Details
#callback ⇒ ^(Zizq::CrontabEntry) -> Zizq::CrontabEntry (readonly)
Callback through which the built entry is passed before being added to the Crontab schedule.
The callback receives the Zizq::CrontabEntry instance and may return an alternative instance to be used after it has done any processing on the entry.
39 40 41 |
# File 'lib/zizq/crontab_entry_builder.rb', line 39 def callback @callback end |
#expression ⇒ String (readonly)
The cron expression for the entry.
23 24 25 |
# File 'lib/zizq/crontab_entry_builder.rb', line 23 def expression @expression end |
#name ⇒ String (readonly)
The name of the entry being built.
20 21 22 |
# File 'lib/zizq/crontab_entry_builder.rb', line 20 def name @name end |
#paused ⇒ Boolean? (readonly)
True if this entry will be paused.
31 32 33 |
# File 'lib/zizq/crontab_entry_builder.rb', line 31 def paused @paused end |
#target ⇒ Zizq::Crontab (readonly)
The Crontab instance onto which entries are applied.
17 18 19 |
# File 'lib/zizq/crontab_entry_builder.rb', line 17 def target @target end |
#timezone ⇒ String? (readonly)
Optional timezone for the entry.
Defaults to the Zizq server timezone when not specified.
28 29 30 |
# File 'lib/zizq/crontab_entry_builder.rb', line 28 def timezone @timezone end |
Instance Method Details
#enqueue(job_class, *args, **kwargs, &block) ⇒ void
This method returns an undefined value.
Enqueue a Zizq::Job or ActiveJob class using Zizq::ActiveJobConfig via this entry.
71 72 73 |
# File 'lib/zizq/crontab_entry_builder.rb', line 71 def enqueue(job_class, *args, **kwargs, &block) push_entry(Zizq.build_enqueue_request(job_class, *args, **kwargs, &block)) end |
#enqueue_bulk {|arg0| ... } ⇒ self
Bulk enqueues are not supported via cron.
98 99 100 |
# File 'lib/zizq/crontab_entry_builder.rb', line 98 def enqueue_bulk(&block) raise NotImplementedError, 'bulk enqueues are not supported via cron' end |
#enqueue_raw(queue:, type:, payload:, **opts) ⇒ void
This method returns an undefined value.
Process a raw job enqueue for this entry.
This is used for low-level or cross-language support.
90 91 92 |
# File 'lib/zizq/crontab_entry_builder.rb', line 90 def enqueue_raw(queue:, type:, payload:, **opts) push_entry(EnqueueRequest.new(queue:, type:, payload:, **opts)) end |
#enqueue_with(**overrides) ⇒ EnqueueWith
Provide common fields to be used when enqueueing a job.
106 107 108 |
# File 'lib/zizq/crontab_entry_builder.rb', line 106 def enqueue_with(**overrides) EnqueueWith.new(self, overrides) end |
#push_entry(req) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/zizq/crontab_entry_builder.rb', line 114 def push_entry(req) if req.ready_at || req.delay raise ArgumentError, 'delayed job are not permitted via cron' end entry = callback.call( CrontabEntry.new( target, name, expression, job: req, timezone:, paused:, ), ) target.entries[entry.name] = entry end |