Kiq v0.6.0 Kiq.Worker behaviour View Source

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()

Link to this section Summary

Callbacks

Build a job for this worker using all default options

The perform/1 function is called with the enqueued arguments

Link to this section Types

Link to this type opts() View Source
opts() :: [
  queue: binary(),
  dead: boolean(),
  expires_in: pos_integer(),
  retry: boolean(),
  unique_for: pos_integer(),
  unique_until: binary()
]

Link to this section Callbacks

Build a job for this worker using all default options.

Any additional arguments that are provided will be merged into the job.

Link to this callback perform(args) View Source
perform(args :: args()) :: any()

The perform/1 function is called with the enqueued arguments.

The return value is not important.