We use cookies

We use cookies to ensure you get the best experience on our website. For more information on how we use cookies, please see our cookie policy.

By clicking "Accept", you agree to our use of cookies.
Learn more.

User GuidePriority

Assigning priority to tasks in Hatchet

Hatchet allows you to assign different priority values to your tasks depending on how soon you want them to run. priority can be set to either 1, 2, or 3, (low, medium, and high, respectively) with relatively higher values resulting in that task being picked up before others of the same type. By default, runs in Hatchet have a priority of 1 (low) unless otherwise specified.

🪓

Priority only affects multiple runs of a single workflow. If you have two different workflows (A and B) and set A to globally have a priority of 3, and B to globally have a priority of 1, this does not guarantee that if there is one task from A and one from B in the queue, that A’s task will be run first.

However, within A, if you enqueue one task with priority 3 and one with priority 1, the priority 3 task will be run first.

A couple of common use cases for assigning priorities are things like:

  1. Having high-priority (e.g. paying, new, etc.) customers be prioritized over lower-priority ones, allowing them to get faster turnaround times on their tasks.
  2. Having tasks triggered via your API run with higher priority than the same tasks triggered by a cron.

Setting priority for a task or workflow

There are a few different ways to set priorities for tasks or workflows in Hatchet.

Workflow-level default priority

First, you can set a default priority at the workflow level:

This will assign the same default priority to all runs of this workflow (and all of the workflow’s corresponding tasks), but will have no effect without also setting run-level priorities, since every run will use the same default.

Priority-on-trigger

When you trigger a run, you can set the priority of the triggered run to override its default priority.

Similarly, you can also assign a priority to scheduled and cron workflows.

In these cases, the priority set on the trigger will override the default priority, so these runs will be processed ahead of lower-priority ones.