faktory_worker_ex v0.7.1 Faktory.Worker behaviour

Create and configure a worker for processing jobs.

It works exatly the same as configuring an Ecto Repo.

defmodule MyFaktoryWorker do
  use Faktory.Worker, otp_app: :my_app
end

# It must be added to your app's supervision tree
defmodule MyApp.Application do
  use Application

  def start(_type, _args) do
    children = [MyFaktoryWorker]
    Supervisor.start_link(children, strategy: :one_for_one)
  end
end

Defaults

See defaults/0 for default worker configuration.

Compile time config

Done with Mix.Config, duh.

use Mix.Config

config :my_app, MyFaktoryWorker,
  host: "foo.bar",
  concurrency: 15
  queues: ["default", "other_queue"]

Runtime config

Can be done with the init/1 callback.

Can be done with environment variable tuples:

use Mix.Config

config :my_app, MyFaktoryWorker,
  host: {:system, "FAKTORY_HOST"} # No default, errors if FAKTORY_HOST doesn't exist
  port: {:system, "FAKTORY_PORT", 1001} # Use 1001 if FAKTORY_PORT doesn't exist

Link to this section Summary

Functions

Return the default worker configuration

Callbacks

Returns a worker's config after all runtime modifications have occurred

Callback for doing runtime configuration

Link to this section Functions

Return the default worker configuration.

iex(1)> Faktory.Worker.defaults
[
  host: "localhost",
  port: 7419,
  middleware: [],
  concurrency: 20,
  queues: ["default"],
  password: nil,
  use_tls: false
]

Link to this section Callbacks

Link to this callback

config()
config() :: Keyword.t()

Returns a worker's config after all runtime modifications have occurred.

iex(1)> MyFaktoryWorker.config
[
  wid: "a2ba187ec640215f",
  host: "localhost",
  port: 7419,
  middleware: [],
  concurrency: 20,
  queues: ["default"],
  password: nil,
  use_tls: false
]

Don't mess with the wid. 🤨

Link to this callback

init(config)
init(config :: Keyword.t()) :: Keyword.t()

Callback for doing runtime configuration.

defmodule MyFaktoryWorker do
  use Faktory.Worker, otp_app: :my_app

  def init(config) do
    config
    |> Keyword.put(:host, "foo.bar")
    |> Keyword.merge(queues: ["default", "other_queue"], concurrency: 10)
  end
end