Creating a worker
- Python
- TypeScript
- Go
Call
hatchet.worker() to create a worker. Pass your tasks or workflows in the workflows list, then call worker.start() to begin processing.worker.py
Worker parameters
A unique name for this worker. Used in the Hatchet UI and logs to identify which worker handled a given task run.
The maximum number of standard task runs the worker may execute concurrently. When all slots are occupied, the worker stops accepting new tasks until a slot is freed.Defaults to
100 in TypeScript and Go. In Python, the default is derived from the registered workflows; if no workflows require a specific slot count, a default of 100 is used.The maximum number of durable task runs the worker may hold concurrently. Durable tasks have their own separate slot pool that does not compete with standard task slots.Defaults to
1000 in TypeScript and Go. In Python, the default is derived from whether any registered workflows contain durable tasks.A dictionary of key/value metadata attached to the worker at startup. Labels are used by worker affinity rules to route tasks to workers that have specific capabilities (for example, a particular ML model loaded into memory).See Worker affinity for details.
A list of workflows or standalone tasks to register with the worker. The worker will only accept task runs for the actions it has registered. In Python you can also call
worker.register_workflow() or worker.register_workflows() after construction.An async generator function that runs alongside the worker. Code before the
yield executes during worker startup; code after the yield runs when the worker shuts down. The yielded value is available to all tasks via ctx.lifespan.See Lifespan below.Worker slots
Slots control how many tasks a worker can run at the same time. When a worker has no free slots, the Hatchet server will not dispatch new tasks to it — those tasks queue until a slot opens or another worker picks them up.- Python
- TypeScript
- Go
Durable slots
Durable tasks use a separate slot pool so that long-running durable tasks waiting on events or sleeping do not starve regular tasks of capacity. Configuredurable_slots independently of slots.
- Python
- TypeScript
- Go
If you register durable tasks on a worker but do not set
durable_slots, Hatchet will automatically allocate a default durable slot pool.Registering workflows and tasks
You can register workflows and tasks when creating the worker or after construction.- Python
- TypeScript
- Go
worker.py
Lifespan
Thelifespan parameter lets you run setup and teardown logic that wraps the entire lifetime of the worker. This is useful for initializing shared resources — database connection pools, ML models, HTTP clients — and making them available to all tasks without re-initializing on every run.
The lifespan function is an async generator. Yield the shared context object; tasks access it via ctx.lifespan.
- Python
worker.py
Starting the worker
- Python
- TypeScript
- Go
worker.start() creates a new event loop and blocks until the worker is stopped by a signal or an error. Call it from your main entry point.SIGTERM and SIGINT gracefully by default — it stops accepting new tasks, waits for in-flight tasks to complete, runs lifespan teardown, then exits.Worker health checks
Hatchet workers expose an optional HTTP health check endpoint. Enable it through your client configuration:HEALTHY once the action listener subprocess is confirmed running, and to UNHEALTHY if the subprocess exits unexpectedly. When UNHEALTHY, the worker initiates a graceful shutdown.
Next steps
Task routing
Control which workers execute which tasks using sticky assignment and priority.
Worker affinity
Route tasks to workers with specific capabilities using labels.