Creating a worker
Create a worker withhatchet.worker(), register your workflows, and then start it.
hatchet.worker() parameters
The name of the worker. The configured namespace is automatically prepended.
Maximum number of standard (non-durable) tasks the worker can run concurrently. When
None, the SDK resolves a default based on the registered workflows.Maximum number of durable task slots. When
None, the SDK resolves a default based on the registered workflows.Key-value labels attached to the worker, used for affinity-based task routing.
Shorthand to register workflows at creation time, equivalent to calling
worker.register_workflows(workflows) after creation.An async generator function that runs setup logic before the worker starts and teardown logic after it stops. See Lifespan below.
Registering workflows
Register workflows after creating the worker:hatchet.worker(workflows=[...]) are registered automatically at creation time.
Starting the worker
Synchronous start (blocking)
worker.start() blocks the calling thread for the lifetime of the worker. The worker creates its own event loop internally.
Lifespan
A lifespan function is an async generator that performs setup before the first task runs and teardown after the worker shuts down. The valueyielded becomes available as ctx.lifespan inside every task.
Worker status
TheWorker.status property returns a WorkerStatus enum value:
| Value | Description |
|---|---|
WorkerStatus.INITIALIZED | Worker created but not yet started. |
WorkerStatus.STARTING | Worker is starting up and registering with the server. |
WorkerStatus.HEALTHY | Worker is running and the action-listener subprocess is alive. |
WorkerStatus.UNHEALTHY | The action-listener subprocess has exited unexpectedly. |
Slot types
Hatchet distinguishes two categories of worker slots:- Standard slots (
slots) — used by regular@hatchet.task()and@workflow.task()tasks. - Durable slots (
durable_slots) — used by@hatchet.durable_task()and@workflow.durable_task()tasks.