Class: Zizq::BulkEnqueue
- Inherits:
-
Object
- Object
- Zizq::BulkEnqueue
- Defined in:
- lib/zizq/bulk_enqueue.rb
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 ⇒ Object
readonly
: Array.
Instance Method Summary collapse
-
#enqueue(job_class, *args, **kwargs, &block) ⇒ Object
Collect a job class enqueue.
-
#enqueue_bulk {|_self| ... } ⇒ Object
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) ⇒ Object
Collect a raw enqueue.
-
#enqueue_with(**overrides) ⇒ Object
Build a scoped enqueue helper that applies the given overrides to a single enqueue inside this bulk block.
-
#initialize ⇒ BulkEnqueue
constructor
: () -> void.
Constructor Details
#initialize ⇒ BulkEnqueue
: () -> void
18 19 20 |
# File 'lib/zizq/bulk_enqueue.rb', line 18 def initialize #: () -> void @requests = [] #: Array[EnqueueRequest] end |
Instance Attribute Details
#requests ⇒ Object (readonly)
: Array
16 17 18 |
# File 'lib/zizq/bulk_enqueue.rb', line 16 def requests @requests end |
Instance Method Details
#enqueue(job_class, *args, **kwargs, &block) ⇒ Object
Collect a job class enqueue. Accepts the same arguments as ‘Zizq.enqueue`.
30 31 32 |
# 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 {|_self| ... } ⇒ Object
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
82 83 84 85 |
# File 'lib/zizq/bulk_enqueue.rb', line 82 def enqueue_bulk(&block) yield self self end |
#enqueue_raw(queue:, type:, payload:, **opts) ⇒ Object
Collect a raw enqueue. Accepts the same arguments as ‘Zizq.enqueue_raw`.
48 49 50 |
# File 'lib/zizq/bulk_enqueue.rb', line 48 def enqueue_raw(queue:, type:, payload:, **opts) @requests << EnqueueRequest.new(queue:, type:, payload:, **opts) end |
#enqueue_with(**overrides) ⇒ Object
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 }
63 64 65 |
# File 'lib/zizq/bulk_enqueue.rb', line 63 def enqueue_with(**overrides) EnqueueWith.new(self, overrides) end |