Workers
Workers in Hatchet are the long-running processes that execute tasks. In the broadest sense, it may be helpful to think of a worker as a simple while loop that receives a new task assignment from Hatchet, executes the task, and reports the results back.
When workers are spun up - in any environment, be it locally, on a VM, etc. - they will register themselves with Hatchet to start receiving and executing tasks.
Declaring a worker
A worker needs a name and a set of tasks (or workflows, more on this later) to register:
When a worker starts, it registers each of its tasks and workflows with Hatchet. From that point on, Hatchet knows to route matching tasks to that worker.
One important note is that multiple workers can register the same task. In this scenario, Hatchet distributes work across all of them, allowing for simple horizontal scaling.
Starting a worker
The fastest way to run a worker during development is with the Hatchet CLI. This handles authentication and hot reloads on code changes:
hatchet worker devOnce the worker starts, you will see logs confirming it is connected:
[INFO] 🪓 -- STARTING HATCHET...
[DEBUG] 🪓 -- 'test-worker' waiting for ['simpletask:step1']
[DEBUG] 🪓 -- acquired action listener: efc4aaf2-...
[DEBUG] 🪓 -- sending heartbeatFor self-hosted engines, there may be additional gRPC configuration options needed. See the Self-Hosting docs for details.
Slots
Every worker has a fixed number of slots that control how many tasks it can run concurrently, which can be configured with the slots option on the worker. For instance, if slots is set to 5, the worker will run up to five tasks concurrently at any time. Any additional tasks wait in the queue until a slot opens up. Slots are a local limit. They protect the individual worker from attempting to run more tasks concurrently than desired, which can help control resource usage by the worker.
The default slot count for workers in Hatchet is 100. In many cases, leaving the default as-is will be perfectly fine, especially when first getting set up with Hatchet.