PhoenixGenApi.WorkerPool.Worker (PhoenixGenApi v1.1.2)

View Source

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
  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.

Summary

Functions

Returns a specification to start this module under a supervisor.

Executes a task on this worker.

Starts a worker process.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

execute(worker_pid, task)

Executes a task on this worker.

Parameters

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

start_link(opts)

Starts a worker process.

Parameters

  • opts - Keyword list with:
    • :pool_name - Name of the parent pool (required)