Callbacks
Last updated
Last updated
Callbacks are used to run specific functions after the success and/or failure of your project run. Callbacks can be provided when instantiating your or when calling the method.
Let's look at an example:
Here's what's happening in this project:
In main.py
, we see that the user wishes to run print_success
upon the project's success and print_failure
upon the project's failure. These are specified in the same module as the project
instance (i.e., in main.py
itself).
Both print_success
and print_failure
do not accept any arguments. This is required.
What if the user wants to run functions that do not live inside inside main.py
)? Let's take a look at two more examples.
Let's say that, instead of living in main.py
, the callbacks live inside callbacks.py
:
In this case, you should be able to import callbacks
directly, since it lives in the same directory as main.py
:
Now, let's assume that the callbacks live inside common/utils.py
:
When specifying the on_success
and on_failure
callbacks, we can use the string representation of the import path:
In this case, we need to ensure that our project has access to the modules within common
. We do this via the package_lookups
keyword argument. This argument takes a list of strings or path-like objects. At runtime, Prism adds these paths to . After the project finishes, these paths are then removed.