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
- Worker starts in idle state
- Pool assigns a task via
execute/2 - Worker executes the task with timeout protection
- Worker notifies pool when done
- 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.
Summary
Functions
Returns a specification to start this module under a supervisor.
Executes a task on this worker.
Starts a worker process.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Executes a task on this worker.
Parameters
worker_pid- The worker process PIDtask- A zero-arity function to execute
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)