faktory_worker_ex v0.7.1 Faktory.Client behaviour
Create and configure a client for enqueing jobs.
It works exatly the same as configuring an Ecto Repo.
defmodule MyFaktoryClient do
use Faktory.Client, 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 = [MyFaktoryClient]
Supervisor.start_link(children, strategy: :one_for_one)
end
end
Defaults
See defaults/0
for default client configuration.
Compile time config
Done with Mix.Config, duh.
use Mix.Config
config :my_app, MyFaktoryClient,
host: "foo.bar",
port: 1000
pool: 10
Runtime config
Can be done with the init/1
callback.
Can be done with environment variable tuples:
use Mix.Config
config :my_app, MyFaktoryClient,
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
Default client
The first client to startup is the default client, unless otherwise specifed by
the :default
option.
For example:
MyJob.perform_async([1, 2, 3]) # Uses default client
MyJob.perform_async([1, 2, 3], client: OtherFaktoryClient) # Uses some other client
Link to this section Summary
Functions
Return the default client configuration
Callbacks
Returns a client's config after all runtime modifications have occurred
Callback for doing runtime configuration
Link to this section Functions
Link to this function
defaults()
defaults()
defaults() :: Keyword.t()
defaults() :: Keyword.t()
Return the default client configuration.
iex(3)> Faktory.Client.defaults
[
host: "localhost",
port: 7419,
pool: 5,
middleware: [],
password: nil,
use_tls: false,
default: false
]
Link to this section Callbacks
Link to this callback
config()
config()
config() :: Keyword.t()
config() :: Keyword.t()
Returns a client's config after all runtime modifications have occurred.
iex(5)> MyFaktoryClient.config
[
port: 1001,
host: "foo.bar",
pool: 10,
middleware: [],
password: nil,
use_tls: false,
default: true
]
Link to this callback
init(config)
Callback for doing runtime configuration.
defmodule MyFaktoryClient do
use Faktory.Client, otp_app: :my_app
def init(config) do
config
|> Keyword.put(:host, "foo.bar")
|> Keyword.merge(port: 1001, pool: 10)
end
end