Class: Zizq::BulkEnqueue

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initializeBulkEnqueue

Returns a new instance of BulkEnqueue.

Signature:

  • () -> void



18
19
20
# File 'lib/zizq/bulk_enqueue.rb', line 18

def initialize #: () -> void
  @requests = [] #: Array[EnqueueRequest]
end

Instance Attribute Details

#requestsArray[EnqueueRequest] (readonly)

Signature:

  • Array[EnqueueRequest]

Returns:



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.

RBS:

  • job_class: Class & Zizq::JobConfig

  • args: Array[untyped]

  • kwargs: Hash[Symbol, untyped]

  • &block: ?(EnqueueRequest) -> void

  • return: void

Parameters:



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

RBS:

  • &block: (BulkEnqueue) -> void

  • return: self

Yields:

Yield Parameters:

Yield Returns:

  • (void)

Returns:

  • (self)


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.

RBS:

  • queue: String

  • type: String

  • payload: untyped

  • priority: Integer?

  • ready_at: Zizq::to_f?

  • retry_limit: Integer?

  • backoff: Zizq::backoff?

  • retention: Zizq::retention?

  • unique_key: String?

  • unique_while: Zizq::unique_scope?

  • batch: Zizq::batch?

  • return: void

Parameters:

  • queue: (String)
  • type: (String)
  • payload: (Object)
  • opts (Object)


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 }

RBS:

  • overrides: Hash[Symbol, untyped]

  • return: EnqueueWith

Parameters:

  • overrides (Object)

Returns:



69
70
71
# File 'lib/zizq/bulk_enqueue.rb', line 69

def enqueue_with(**overrides)
  EnqueueWith.new(self, overrides)
end