# `PhoenixGenApi.WorkerPool.Worker`
[🔗](https://github.com/ohhi-vn/phoenix_gen_api/blob/main/lib/phoenix_gen_api/worker_pool/worker.ex#L1)

Individual worker process for executing tasks.

Workers are managed by the WorkerPool and execute tasks one at a time.
When a task completes, the worker notifies the pool that it's available
for more work.

## Lifecycle

1. Worker starts in idle state
2. Pool assigns a task via `execute/2`
3. Worker executes the task with timeout protection
4. Worker notifies pool when done
5. Returns to idle state

## Error Handling

If a task raises an exception, the worker catches it, logs the error,
and continues running. The pool is notified that the worker is done
even if the task failed.

## Circuit Breaker

Workers track consecutive failures. If failures exceed the threshold,
the worker enters a "circuit open" state and rejects new tasks for a
cooldown period. This prevents cascading failures when downstream
services are unhealthy.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `execute`

Executes a task on this worker.

## Parameters

  - `worker_pid` - The worker process PID
  - `task` - A zero-arity function to execute

# `start_link`

Starts a worker process.

## Parameters

  - `opts` - Keyword list with:
    - `:pool_name` - Name of the parent pool (required)
    - `:task_timeout` - Task execution timeout in milliseconds (default: 30000)

---

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