Bedrock.JobQueue.Consumer.Worker (bedrock_job_queue v0.2.0)
View SourceJob execution logic.
Provides the execute/2 function that runs job modules' perform/2 callbacks with timeout protection. Used directly by Manager via Task.Supervisor.
Workers are configured via the JobQueue module's workers map:
defmodule MyApp.JobQueue do
use Bedrock.JobQueue,
otp_app: :my_app,
repo: MyApp.Repo,
workers: %{
"email:send" => MyApp.Jobs.SendEmail,
"order:process" => MyApp.Jobs.ProcessOrder
}
end
Summary
Functions
Executes a job and returns the result.
Functions
@spec execute(Bedrock.JobQueue.Item.t(), map()) :: term()
Executes a job and returns the result.
Called from a Task spawned by Manager. Looks up the handler for the item's topic from the workers map and executes it with timeout protection.
Return Values
Returns the result from the job module's perform/2 callback, or an error:
:ok- Job completed successfully, will be removed from queue{:ok, result}- Job completed with result (logged but otherwise same as:ok){:error, reason}- Job failed, will be requeued with backoff{:discard, reason}- Job failed permanently, removed without retry{:snooze, delay_ms}- Reschedule for later and count it in retry accounting{:error, :timeout}- Job exceeded timeout, will be requeued{:discard, :no_handler}- No worker configured for this topic
Timeout
Jobs are executed with a timeout (default 30 seconds). If the job module
implements timeout/0, that value is used instead. On timeout, the job
is killed and {:error, :timeout} is returned.