Module: Axn::Async::BatchEnqueue::DSL

Defined in:
lib/axn/async/batch_enqueue.rb

Overview

DSL methods for batch enqueueing

Instance Method Summary collapse

Instance Method Details

#enqueue_all(**static_args) ⇒ String

Batch enqueue jobs for this action.

Validates async is configured, validates static args, then executes iteration asynchronously via EnqueueAllOrchestrator.

Fields with ‘model:` declarations are automatically inferred for iteration. You can override iteration by passing enumerables (to replace source) or scalars (to make fields static) as kwargs.

Parameters:

  • static_args (Hash)

    Arguments to pass to every enqueued job.

    • Scalar values: Treated as static args (passed to all jobs)

    • Enumerable values: Treated as iteration sources (overrides configured sources)

    • Exception: Arrays/Sets are static when field expects enumerable type

Returns:

  • (String)

    Job ID from the async adapter

Raises:

  • (NotImplementedError)

    If async is not configured

  • (MissingEnqueuesEachError)

    If expects exist but no iteration config found

  • (ArgumentError)

    If required static fields are missing



76
77
78
# File 'lib/axn/async/batch_enqueue.rb', line 76

def enqueue_all(**static_args)
  EnqueueAllOrchestrator.enqueue_for(self, **static_args)
end

#enqueues_each(field, from: nil, via: nil, &filter_block) ⇒ Object

Declare a field to iterate over for batch enqueueing.

Note: Fields with ‘model:` declarations are automatically inferred, so `enqueues_each` is only needed to override defaults, add filtering, or iterate non-model fields.

Parameters:

  • field (Symbol)

    The field name from expects to iterate over

  • from (Proc, Symbol, nil) (defaults to: nil)

    The source collection.

    • Proc/lambda: Called to get the collection

    • Symbol: Method name on the action class

    • nil: Inferred from field’s ‘model:` declaration (Model.all)

  • via (Symbol, nil) (defaults to: nil)

    Optional attribute to extract from each item (e.g., :id)

  • block (Proc, nil)

    Optional filter block - return truthy to enqueue, falsy to skip



93
94
95
# File 'lib/axn/async/batch_enqueue.rb', line 93

def enqueues_each(field, from: nil, via: nil, &filter_block)
  self._batch_enqueue_configs += [Config.new(field:, from:, via:, filter_block:)]
end