Background job worker. Polls the JobQueue every @poll_interval ms,
claims the next available job, executes it, and updates its status.
Designed to run in a pool via Core.Workers.WorkerPool. Each worker
process operates independently — there is no cross-worker coordination
needed because JobQueue serializes claim_next/1 via GenServer.call.
Custom workers
To create a domain-specific worker, copy this module and override
perform_work/1. You must keep the same start_link/1 signature so
WorkerPool can start it. The worker should read :id and :pool from
opts and register under a unique name derived from the pool.
Options (passed by WorkerPool)
:id– unique integer ID within the pool:queue– theJobQueuename to poll (default:Core.Workers.JobQueue):pool– theWorkerPoolname this worker belongs to
Execution flow
- The worker receives
:work_available(immediate wake-up fromJobQueue) or:work(fallback timer every@poll_intervalms). - It calls
JobQueue.claim_next/1to atomically claim the next:queuedjob. - It calls
perform_work/1with the job struct — this is your hook. - On success it calls
JobQueue.mark_done/3; on exception it callsJobQueue.mark_failed/3.
Telemetry events emitted
[:core, :job, :start]— when a job begins executing metadata:%{job_id: id, attempt: n, payload: map}[:core, :job, :stop]— when a job completes successfully measurements:%{duration: native_time}metadata:%{job_id: id}[:core, :job, :error]— when a job raises an exception measurements:%{duration: native_time}metadata:%{job_id: id, error: string}
Summary
Functions
Returns a specification to start this module under a supervisor.