Invoking Tasks From Other Services
While Hatchet recommends importing your workflows and standalone tasks directly to use for triggering runs, this only works in a monorepo or similar setups where you have access to those objects. However, it’s common to have a polyrepo, have code written in multiple languages, or otherwise not be able to import your workflows and standalone tasks directly. Hatchet provides first-class, type-safe support for handling these cases as well, with only minor code duplication, to allow you to trigger your tasks from anywhere in a type-safe way.
Creating a “Stub” Task on your External Service (Recommended)
The recommended way to trigger a run from a service where you cannot import the workflow or standalone task definition directly is to create a “stub” task or workflow on your external service. This is a Hatchet task or workflow that has the same name and input/output types as the task you want to trigger on your Hatchet worker, but without the function or other configuration.
This allows you to have a polyglot, fully typed interface with full SDK support.
Note that this approach requires code duplication, which can break type safety. For instance, if the input type to your workflow changes, you need to remember to also change the type passed to the stub. Some ways to mitigate risks here are helpful comments reminding developers to keep these types in sync, code generation tools, and end-to-end tests.