View Source Kiq.Worker behaviour (Kiq v0.7.3)
Defines a behavior and macro to guide the creation of worker modules.
Worker modules do the work of processing a job. At a minimum they must define
a perform
function, which will be called with the arguments that were
enqueued with the Kiq.Job
.
Defining Workers
Define a worker to process jobs in the events
queue:
defmodule MyApp.Workers.Business do
use Kiq.Worker, queue: "events", retry: 10, dead: false
@impl Kiq.Worker
def perform(args) do
IO.inspect(args)
end
end
The perform/1
function will always receive a list of arguments. In this
example the worker will simply inspect any arguments that are provided.
Enqueuing Jobs
All workers implement a new/1
function that converts a list of arguments
into a Kiq.Job
that is suitable for enqueuing:
["doing", "business"]
|> MyApp.Workers.Business.new()
|> MyApp.Kiq.enqueue()
Summary
Callbacks
Build a job for this worker using all default options.
The perform/1
function is called with the enqueued arguments.
Types
@type args() :: [any()]
@type opts() :: [ queue: binary(), dead: boolean(), expires_in: pos_integer(), retry: boolean(), unique_for: pos_integer(), unique_until: binary() ]
Callbacks
Build a job for this worker using all default options.
Any additional arguments that are provided will be merged into the job.
The perform/1
function is called with the enqueued arguments.
The return value is not important.