shigoto_batch (shigoto v1.9.10)

View Source

Batch/workflow system for Shigoto. Groups jobs into batches with completion and discard callbacks.

Usage

%% Create a batch with a callback worker
{ok, Batch} = shigoto:new_batch(#{
    callback_worker => my_batch_callback,
    callback_args => #{<<\"report_id\">> => 42}
}),
BatchId = maps:get(id, Batch),

%% Insert jobs into the batch
shigoto:insert(#{worker => step_one, args => #{}, batch => BatchId}),
shigoto:insert(#{worker => step_two, args => #{}, batch => BatchId}),

%% When all jobs complete, my_batch_callback:perform/1 is called
%% with the callback_args. If any job is discarded, the batch
%% state changes to 'callback_discarding' and the callback is
%% called with an added <<\"_batch_event\">> => <<\"discard\">> key.

Summary

Functions

Create a new batch.

Get a batch by ID.

Increment total job count for a batch.

Record a completed job in the batch. May trigger callback.

Record a discarded job in the batch. May trigger callback.

Functions

create(Pool, Opts)

-spec create(atom(), map()) -> {ok, map()} | {error, term()}.

Create a new batch.

get(Pool, BatchId)

-spec get(atom(), integer()) -> {ok, map()} | {error, not_found | term()}.

Get a batch by ID.

increment_total(Pool, BatchId)

-spec increment_total(atom(), integer()) -> ok | {error, term()}.

Increment total job count for a batch.

job_completed(Pool, BatchId)

-spec job_completed(atom(), integer()) -> ok | {error, term()}.

Record a completed job in the batch. May trigger callback.

job_discarded(Pool, BatchId)

-spec job_discarded(atom(), integer()) -> ok | {error, term()}.

Record a discarded job in the batch. May trigger callback.