Callbacks¶
Airflow callback functions are often used to send emails, slack messages, or other notifications when a task fails, succeeds, or is retried. They can also run any general Python function.
Modules:
Name | Description |
---|---|
smtp |
|
Classes:
Name | Description |
---|---|
OrbiterCallback |
Represents an Airflow |
orbiter.objects.callbacks.OrbiterCallback ¶
Represents an Airflow
callback function,
which might be used in DAG.on_failure_callback
, or Task.on_success_callback
, or etc.
Can be instantiated directly as a bare callback function (with no arguments):
>>> from orbiter.objects.dag import OrbiterDAG
>>> from orbiter.objects.include import OrbiterInclude
>>> my_callback = OrbiterCallback(
... function="my_callback",
... imports=[OrbiterRequirement(module="my_callback", names=["my_callback"])],
... orbiter_includes={OrbiterInclude(filepath="my_callback.py", contents="...")}
... )
>>> OrbiterDAG(dag_id='', file_path='', on_failure_callback=my_callback)
... # doctest: +ELLIPSIS
from airflow import DAG
from my_callback import my_callback
...
with DAG(... on_failure_callback=my_callback):
or be subclassed:
>>> class OrbiterMyCallback(OrbiterCallback):
... function: str = "my_callback"
... foo: str
... bar: str
... render_attributes: RenderAttributes = ["foo", "bar"]
>>> OrbiterMyCallback(foo="fop", bar="bop")
my_callback(foo='fop', bar='bop')
Parameters:
Name | Type | Description |
---|---|---|
function |
str
|
The name of the function to call |
**OrbiterBase |
OrbiterBase inherited properties |
orbiter.objects.callbacks.smtp ¶
Classes:
Name | Description |
---|---|
OrbiterSmtpNotifierCallback |
orbiter.objects.callbacks.smtp.OrbiterSmtpNotifierCallback ¶
Note
Use smtp_conn_id
and reference an SMTP Connection.
You can use the **conn_id("SMTP", conn_type="smtp")
utility function to set both properties at once.
>>> [_import] = OrbiterSmtpNotifierCallback(to="foo@test.com").imports; _import
OrbiterRequirement(names=[send_smtp_notification], package=apache-airflow-providers-smtp, module=airflow.providers.smtp.notifications.smtp, sys_package=None)
>>> OrbiterSmtpNotifierCallback(to="foo@test.com", from_email="bar@test.com", subject="Hello", html_content="World")
send_smtp_notification(to='foo@test.com', from_email='bar@test.com', smtp_conn_id='SMTP', subject='Hello', html_content='World')
>>> OrbiterSmtpNotifierCallback(to=["foo@test.com", "baz@test.com"], from_email="bar@test.com", subject="Hello", html_content="World")
send_smtp_notification(to=['foo@test.com', 'baz@test.com'], from_email='bar@test.com', smtp_conn_id='SMTP', subject='Hello', html_content='World')
Parameters:
Name | Type | Description |
---|---|---|
to |
str | Sequence[str]
|
The email address to send to |
from_email |
str, optional
|
The email address to send from |
smtp_conn_id |
str, optional
|
The connection id to use (Note: use the |
subject |
str, optional
|
The subject of the email |
html_content |
str, optional
|
The content of the email |
cc |
str | Sequence[str], optional
|
The email address to cc |
**OrbiterBase |
OrbiterBase inherited properties |