Class: Zizq::BulkEnqueue
- Inherits:
-
Object
- Object
- Zizq::BulkEnqueue
- Defined in:
- lib/zizq/bulk_enqueue.rb,
sig/generated/zizq/bulk_enqueue.rbs
Overview
Builder for collecting multiple job params to be sent as a single bulk
request via Zizq.enqueue_bulk.
Zizq.enqueue_bulk do |b|
b.enqueue(MyApp::FooJob, 42)
b.enqueue(MyApp::OtherJob, 42, x: 7)
end
Instance Attribute Summary collapse
- #requests ⇒ Array[EnqueueRequest] readonly
Instance Method Summary collapse
-
#enqueue(job_class, *args, **kwargs, &block) ⇒ void
Collect a job class enqueue.
-
#enqueue_bulk {|arg0| ... } ⇒ self
Nested bulk is a no-op — we're already inside a bulk block, so we just yield this same builder.
-
#enqueue_raw(queue:, type:, payload:, **opts) ⇒ void
Collect a raw enqueue.
-
#enqueue_with(**overrides) ⇒ EnqueueWith
Build a scoped enqueue helper that applies the given overrides to a single enqueue inside this bulk block.
-
#initialize ⇒ BulkEnqueue
constructor
A new instance of BulkEnqueue.
Constructor Details
#initialize ⇒ BulkEnqueue
Returns a new instance of BulkEnqueue.
18 19 20 |
# File 'lib/zizq/bulk_enqueue.rb', line 18 def initialize #: () -> void @requests = [] #: Array[EnqueueRequest] end |
Instance Attribute Details
#requests ⇒ Array[EnqueueRequest] (readonly)
16 17 18 |
# File 'lib/zizq/bulk_enqueue.rb', line 16 def requests @requests end |
Instance Method Details
#enqueue(job_class, *args, **kwargs, &block) ⇒ void
This method returns an undefined value.
Collect a job class enqueue. Accepts the same arguments as
Zizq.enqueue.
30 31 32 33 34 35 36 37 |
# File 'lib/zizq/bulk_enqueue.rb', line 30 def enqueue(job_class, *args, **kwargs, &block) @requests << Zizq.build_enqueue_request( job_class, *args, **kwargs, &block ) end |
#enqueue_bulk {|arg0| ... } ⇒ self
Nested bulk is a no-op — we're already inside a bulk block, so we
just yield this same builder. This exists to satisfy the
_EnqueueTarget interface, which lets EnqueueWith#enqueue_bulk
work uniformly against both the top-level Zizq module and a
BulkEnqueue instance without branching on target type.
Zizq.enqueue_bulk do |b|
b.enqueue_with(priority: 0).enqueue_bulk do |b2|
b2.enqueue(MyJob, 1)
b2.enqueue(MyJob, 2)
end
end
88 89 90 91 |
# File 'lib/zizq/bulk_enqueue.rb', line 88 def enqueue_bulk(&block) yield self self end |
#enqueue_raw(queue:, type:, payload:, **opts) ⇒ void
This method returns an undefined value.
Collect a raw enqueue. Accepts the same arguments as
Zizq.enqueue_raw.
54 55 56 |
# File 'lib/zizq/bulk_enqueue.rb', line 54 def enqueue_raw(queue:, type:, payload:, **opts) @requests << EnqueueRequest.new(queue:, type:, payload:, **opts) end |
#enqueue_with(**overrides) ⇒ EnqueueWith
Build a scoped enqueue helper that applies the given overrides to a single enqueue inside this bulk block. Sugar for the block form:
b.enqueue_with(ready_at: Time.now + 3600).enqueue(OtherJob, 42)
is equivalent to:
b.enqueue(OtherJob, 42) { |req| req.ready_at = Time.now + 3600 }
69 70 71 |
# File 'lib/zizq/bulk_enqueue.rb', line 69 def enqueue_with(**overrides) EnqueueWith.new(self, overrides) end |