Belay.Batch (Belay v1.0.0)

Copy Markdown View Source

Insert a group of jobs and run a callback when the whole group has finished — thin, transparent sugar over Belay.Workflow.

{:ok, batch_id, jobs} =
  Belay.Batch.insert(MyBelay, changeset_list,
    on_complete: MyApp.Notify.new(%{"channel" => "#imports"}))

The callback job runs once every batch member is terminal, whatever the outcomes were, and receives "batch_id" merged into its input — read Belay.Batch.status/2 there for the final counts. Batch members are ordinary workflow jobs: cancel them, retry them, and inspect them with the normal APIs.

Summary

Functions

Insert buildables as a batch. Options

All jobs in the batch, callback included.

Batch status: %{total:, state_counts:, done?:} (callback included).

Functions

insert(name, buildables, opts \\ [])

@spec insert(Belay.instance(), [Belay.buildable()], keyword()) ::
  {:ok, String.t(), %{required(String.t()) => Belay.Job.t()}}

Insert buildables as a batch. Options:

  • :on_complete — a Worker.new/2 build to run after every member finishes (any outcome)
  • :batch_id — override the generated id

Returns {:ok, batch_id, jobs_by_name}.

jobs(name, batch_id)

@spec jobs(Belay.instance(), String.t()) :: [Belay.Job.t()]

All jobs in the batch, callback included.

status(name, batch_id)

Batch status: %{total:, state_counts:, done?:} (callback included).