Defines a background job worker.
Example
defmodule MyApp.Workers.SendEmail do
use Fleet.Worker, queue: :mailers, max_attempts: 3
@impl Fleet.Worker
def perform(%Fleet.Job{args: %{"to" => to}}) do
MyApp.Mailer.send(to)
end
end
Summary
Callbacks
Processes multiple jobs together in a single batch.
Functions
Calculates standard exponential backoff with jitter in seconds.
Callbacks
@callback backoff(job :: Fleet.Job.t()) :: pos_integer()
@callback perform(job :: Fleet.Job.t()) :: :ok | {:ok, term()} | {:error, term()} | {:snooze, pos_integer()} | {:cancel, term()} | term()
@callback perform_batch(jobs :: [Fleet.Job.t()]) :: :ok | {:ok, term()} | {:error, term()} | term()
Processes multiple jobs together in a single batch.
When defined on a worker, Broadway groups messages according to the queue's
:batch_size and :batch_timeout settings before calling this callback.
Ideal for bulk external API calls or bulk database persistence (e.g. using ecto_unnest).
Functions
@spec default_backoff(integer()) :: pos_integer()
Calculates standard exponential backoff with jitter in seconds.