# `FaktoryWorker`
[🔗](https://github.com/opt-elixir/faktory_worker/blob/main/lib/faktory_worker.ex#L1)

The `FaktoryWorker` module provides everything required to setup workers for sending and fetching jobs.

It is expected that FaktoryWorker will be configured and started as part of a supervision tree. Multiple instances of
FaktoryWorker can be configured by providing the `:name`  option which must be unique.

This module can either be configured using all default options.

```elixir
children = [
  FaktoryWorker
]
```

Or by using the two element tuple format accepting a list of options as the second element.

```elixir
children = [
  {FaktoryWorker, [name: :faktory_test, ...]}
]
```

For a full list of configuration options see the [Configuration](configuration.html) documentation.

# `command`

```elixir
@type command() :: FaktoryWorker.Protocol.protocol_command()
```

# `send_command_opt`

```elixir
@type send_command_opt() :: {:faktory_name, module()} | {:timeout, pos_integer()}
```

# `attach_default_telemetry_handler`

```elixir
@spec attach_default_telemetry_handler() :: :ok | {:error, :already_exists}
```

Attaches the default telemetry handler provided by FaktoryWorker.

This function attaches the default telemetry handler provided by FaktoryWorker that
outputs log messages for each of the events emitted by FaktoryWorker.

For a full list of events see the [Logging](logging.html) documentation.

# `send_command`

```elixir
@spec send_command(command(), [send_command_opt()]) ::
  FaktoryWorker.Connection.response() | {:error, :timeout}
```

Send a command to the Faktory server.

In most cases, `FaktoryWorker` handles sending commands on your behalf.
However, there are some APIs (such as Enterprise Batches and Tracking)
where it's useful to send a command directly.

The full list of supported commands is available in
`FaktoryWorker.Protocol.protocol_command()`. It is left to the caller to
verify that command arguments are valid.

## Options

- `faktory_name` the Faktory instance to use (default: FaktoryWorker)
- `timeout` how long to wait for a response, in ms (default: 5000)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
