Reference tasks
A reference_task references tasks that have already been defined, serialized, and registered. You can reference tasks from other projects and create workflows that use tasks declared by others. These tasks can be in their own containers, python runtimes, flytekit versions, and even different languages.
Reference tasks cannot be run locally. To test locally, mock them out.
Example
-
Create a file called
task.py
and insert this content into it:import union @union.task def add_two_numbers(a: int, b: int) -> int: return a + b
-
Register the task:
$ union register --project flytesnacks --domain development --version v1 task.py
-
Create a separate file
wf_ref_task.py
and copy the following code into it:from flytekit import reference_task @reference_task( project="flytesnacks", domain="development", name="task.add_two_numbers", version="v1", ) def add_two_numbers(a: int, b: int) -> int: ... @union.workflow def wf(a: int, b: int) -> int: return add_two_numbers(a, b)
-
Register the
wf
workflow:$ union register --project flytesnacks --domain development wf_ref_task.py
-
In the Union.ai UI, run the workflow
wf_ref_task.wf
.