CurrentRun.ref has two important jobs.

First, it's used to reference the output of tasks within your project. Remember, tasks have to return a non-null output (either themselves, if the task is a decorated function or via their run method if the task is a class). At runtime, Prism stores references to these outputted objects and makes them accessible via CurrentRun.ref(...).

Second, it's used to build a dependency graph between tasks. Put another way, Prism parses the CurrentRef.ref(...) calls and figures out the order in which tasks need to be run — if taskB calls CurrentRef.ref("taskA") in its body, then Prism knows to run taskA before taskB.

Here's the full method definition:

CurrentRun.ref(task_id: str) -> Any:
    Get the output of task with ID `task_id`

        task_id: ID of task from which to retrieve output
        the output of the inputted `task_id`
        prism.exception.RefDoesNotExistException if the task ID is not found


# tasks/

import prism.task

class HelloWorld(prism.task.PrismTask):
    def run(self):
        test_str = "Hello, world!"
        return test_str
# tasks/

import prism.task
from prism.runtime import CurrentRun

class SecondTask(prism.task.PrismTask):
    def run(self):
        hello_world_str = CurrentRun.ref("hello_world.HelloWorld")  # default task ID set by Prism
        additional_details = "\n" + "This is a Prism project"!
        return hello_world_str + additional_details

Our CurrentRun.ref() is located in the second task. We did not specify any custom task ID in our HelloWorld task, so we need to reference the default task ID that Prism sets — <module_name>.<class name>.

Last updated