GoodJob.Bulk (good_job v1.0.0)

Copy Markdown View Source

Buffers and enqueues multiple jobs together.

This mirrors the upstream GoodJob::Bulk API:

  • capture/1 captures jobs enqueued within a block.
  • enqueue/1 captures jobs and inserts them atomically in one transaction.
  • enqueue/1 also accepts a list of %GoodJob.Job.Instance{}.

Summary

Functions

Adds a job entry to the current buffer.

Returns true when the current process is buffering jobs.

Captures jobs enqueued inside the given function.

Atomically enqueues jobs.

Types

entry()

@type entry() :: %{job_attrs: map(), callback_module: module() | nil, opts: keyword()}

Functions

add(entry)

@spec add(entry()) :: {:ok, :buffered} | {:error, :not_buffering}

Adds a job entry to the current buffer.

This is used internally by GoodJob.enqueue/3.

buffering?()

@spec buffering?() :: boolean()

Returns true when the current process is buffering jobs.

capture(fun)

@spec capture((-> any())) :: [entry()]

Captures jobs enqueued inside the given function.

Returns captured job entries.

enqueue(fun)

@spec enqueue((-> any()) | [GoodJob.Job.Instance.t()]) ::
  {:ok, [GoodJob.Job.t()]} | {:error, any()}

Atomically enqueues jobs.

Accepts either:

  • a function that enqueues jobs (perform_later/1, GoodJob.enqueue/3, etc.)
  • a list of %GoodJob.Job.Instance{}