-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e4bb6a4
commit 5522a8a
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
.. _callbacks: | ||
|
||
Callbacks | ||
========= | ||
|
||
Cosmos supports callback functions that execute at the end of a task's execution when using ``ExecutionMode.LOCAL``. | ||
These callbacks can be used for various purposes, such as uploading files from the target directory to remote | ||
storage. While this feature has been available for some time, users may not be fully aware of its capabilities. | ||
|
||
With the Cosmos 1.8.0 release, several helper functions were added in the ``cosmos/io.py`` module. These functions | ||
provide examples of callback functions that can be hooked into Cosmos DAGs to upload files from the project’s | ||
target directory to remote cloud storage providers such as AWS S3, GCP GS, and Azure WASB. | ||
|
||
Example: Using Callbacks with a Single Operator | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
To demonstrate how to specify a callback function for uploading files from the target directory, here’s an example | ||
using a single operator in an Airflow DAG: | ||
|
||
.. literalinclude:: ../../dev/dags/example_operators.py | ||
:language: python | ||
:start-after: [START single_operator_callback] | ||
:end-before: [END single_operator_callback] | ||
|
||
Example: Using Callbacks with ``remote_target_path`` (Airflow 2.8+) | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
If you're using Airflow 2.8 or later, you can leverage the :ref:`remote_target_path` configuration to upload files | ||
from the target directory to a remote storage. Below is an example of how to define a callback helper function in your | ||
``DbtDag`` that utilizes this configuration: | ||
|
||
.. literalinclude:: ../../dev/dags/cosmos_callback_dag.py | ||
:language: python | ||
:start-after: [START cosmos_callback_example] | ||
:end-before: [END cosmos_callback_example] | ||
|
||
Custom Callbacks | ||
~~~~~~~~~~~~~~~~ | ||
|
||
The helper functions introduced in Cosmos 1.8.0 are just examples of how callback functions can be written and passed | ||
to Cosmos DAGs. Users are not limited to using these predefined functions — they can also create their own custom | ||
callback functions to meet specific needs. These custom functions can be provided to Cosmos DAGs, where they will | ||
receive the path to the cloned project directory and the Airflow task context, which includes DAG and task instance | ||
metadata. | ||
|
||
Limitations and Contributions | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
|
||
Currently, callback support is available only when using ``ExecutionMode.LOCAL``. Contributions to extend this | ||
functionality to other execution modes are welcome and encouraged. You can reference the implementation for | ||
``ExecutionMode.LOCAL`` to add support for other modes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters