tasks

In the previous section, we saw that tasks needs to have two parameters: tasks, and hooks:

# modules/hello_world.py

import prism.task
import prism.target

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

Both are critical for Prism to run, and Prism will throw an error if it finds a task without both of the parameters.

So what does tasks do? Simply put, it allows users to reference and access other tasks' outputs via the ref(...) function. This is the most important function in Prism. It is impossible to build even moderately complex workflows without it.

Important: To retrieve the output of a different task, simply pass in the module name where that tasks lives, e.g., tasks.ref("<module name here>").

Let's say that you want to create a new task that builds off of the "Hello, world!" string created in task HelloWorld above. You could do that as follows:

# modules/second_task.py

import prism.task
import prism.target

class SecondTask(prism.task.PrismTask):
    
    def run(self, tasks, hooks):
        hello_world_str = tasks.ref("hello_world")
        additional_details = "\n" + "This is a Prism project"!
        return hello_world_str + additional_details

Important: in previous versions of Prism,tasks.ref() argument required the .py suffix (e.g., tasks.ref('hello_world.py')). Starting in version 0.2.0rc1, this suffix should be removed from the argument. In other words:

tasks.ref('hello_world.py') --> tasks.ref('hello_world')

If you leave the .py suffix in, then Prism will throw a warning.

Under the hood, Prism does three things:

  1. It parses each file and computes all tasks.ref(...) calls.

  2. Then, it builds a dependency graph based on which files reference others. In the above example, Prism knows that the task in hello_world.py should be run before the task in second_task.py.

  3. It keeps track of the return value for each task and spits out the desired task's return value for each tasks.ref(...) call.

Important: tasks.ref(...) is one of the most important functions in Prism – it is impossible to build event moderately complex workflows without it.

Last updated