faktory_worker_ex v0.7.1 Faktory.Job behaviour

Use this module to create your job processors.

Getting started

All that is required is to define a perform function that takes zero or more arguments.

defmodule MyFunkyJob do
  use Faktory.Job

  def perform(arg1, arg2) do
    # ... do something ...
  end
end

# To enqueue jobs of this type.
MyFunkyJob.perform_async([1, "foo"])

IMPORTANT: perform_async takes a list who's size must match exactly the airty of perform.

Configuring

You can configure various aspects of the job by passing a keyword list to faktory_options/1.

defmodule MyFunkyJob do
  use Faktory.Job

  faktory_options queue: "default", retry: 25, backtrace: 0

  # ...
end

See faktory_options/0 for available options and defaults.

Runtime overrides

You can override faktory_options when enqueuing a job.

MyFunkyJob.perform_async([1, "foo"], queue: "not_default")
MyFunkyJob.perform_async([2, "bar"], retry: 0)

Link to this section Summary

Functions

Set default options for all jobs of this type

Callbacks

Returns the default options for a given job module

Link to this section Types

Link to this type

job()
job() :: map()

Link to this section Functions

Link to this macro

faktory_options(options) (macro)
faktory_options(Keyword.t()) :: term()

Set default options for all jobs of this type.

For all valid options and their defaults, see faktory_options/0.

Link to this section Callbacks

Link to this callback

faktory_options()
faktory_options() :: options :: Keyword.t()

Returns the default options for a given job module.

iex(5)> MyFunkyJob.faktory_options
[
  queue: "default",
  jobtype: "MyFunkyJob",
  retry: 25,
  middleware: [],
  backtrace: 10
]
Link to this callback

perform_async(args, options)
perform_async(args :: [any()], options :: Keyword.t() | []) :: job()

Enqueue a job.

options can override any options specified by faktory_options/1.

For all valid options, see faktory_options/0.

job_args = [123, "abc"]
MyJob.perform_async(job_args)
MyJob.perform_async(job_args, queue: "not_default" jobtype: "Worker::MyJob")