Hatchet TypeScript V1 Migration Guide
This guide will help you migrate Hatchet workflows from the V0 SDK to the V1 SDK.
Introductory Example
First, we’ve exposed a new hatchet.task
method in the V1 SDK for single function tasks.
DAGs are still defined as workflows, but they can now be declared using the hatchet.workflow
method.
You can now run work for tasks and workflows by directly interacting with the returned object.
There are a few important things to note when migrating to the new SDK:
- The new SDK uses a factory pattern (shown above) for creating tasks and workflows, which we’ve found to be more ergonomic than the previous SDK.
- The old method of defining tasks will still work in the new SDK, but we recommend migrating over to the new method shown above for improved type checking and for access to new features.
- New features of the SDK, such as the new durable execution features rolled out in V1, will only be accessible from the new
TaskDeclaration
object in the new SDK.
Since the old pattern for declaring tasks will still work in the new SDK, we recommend migrating existing tasks to the new patterns in V1 gradually.
Fanout Example
The new SDK also provides improved type support for spawning child tasks from around the codebase. Consider the following example:
First, we declare a child task:
Next, we spawn that child from a parent task:
In this example, the compiler knows what to expect for the types of input
and ctx
for each of the tasks, as well as the type of the input of the child
task when spawning it from the parent
task.