# `Celery.Worker`
[🔗](https://github.com/hacktobeer/celery-elixir/blob/v0.1.0/lib/celery/worker.ex#L1)

Celery Worker / Consumer OTP `GenServer` (ported from `celery.worker`).

Consumes Celery task messages from Redis (or `memory://` in tests) via `Kombu`,
decodes Protocol v1 and v2 task messages, schedules ETA/countdown tasks, enforces
concurrency limits, executes tasks through `Celery.Tracer`, stores results in
`Celery.Backend.Redis`, and optionally listens for `Kombu.Pidbox` control commands.

## Starting a Worker

```elixir
celery = Celery.new(
  broker: "redis://localhost:6379/0",
  backend: "redis://localhost:6379/0",
  include: ["src.tasks"]
)

{:ok, worker} = Celery.Worker.start_link(app: celery, concurrency: 4)
```

# `t`

```elixir
@type t() :: pid()
```

# `active`

```elixir
@spec active(GenServer.server()) :: [map()]
```

Returns the list of currently executing task requests (`inspect.active`).

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `reserved`

```elixir
@spec reserved(GenServer.server()) :: [map()]
```

Returns the list of prefetched/reserved task requests (`inspect.reserved`).

# `revoke`

```elixir
@spec revoke(GenServer.server(), String.t() | [String.t()], keyword()) :: :ok
```

Revokes one or more task IDs on this worker.

# `revoked`

```elixir
@spec revoked(GenServer.server()) :: [String.t()]
```

Returns the list of revoked task IDs on this worker (`inspect.revoked`).

# `scheduled`

```elixir
@spec scheduled(GenServer.server()) :: [map()]
```

Returns the list of ETA-scheduled task requests (`inspect.scheduled`).

# `start_link`

```elixir
@spec start_link(keyword()) :: GenServer.on_start()
```

Starts a `Celery.Worker` linked to the calling process.

## Options
- `:app` - `%Celery{}` instance (required, or built from remaining options)
- `:queues` - list of queue names or `%Kombu.Queue{}` structs to consume from
- `:hostname` - worker node hostname (default `"celery@<host>"`)
- `:concurrency` - maximum number of concurrent task processes (default `app.config.worker_concurrency`)
- `:poll_interval` - poll interval in milliseconds (default `25`)
- `:enable_remote_control` - whether to start a `Kombu.Pidbox.Node` listener (default `false`)
- `:notify` - optional PID to receive `{:celery_task_done, task_id, outcome}` events
- `:name` - optional GenServer registration name

# `stats`

```elixir
@spec stats(GenServer.server()) :: map()
```

Returns worker statistics (`inspect.stats`).

# `stop`

```elixir
@spec stop(GenServer.server(), timeout()) :: :ok
```

Stops a running `Celery.Worker` gracefully.

---

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