Adding Alerts for Workflow

Pre-Requisites

Setup a Notification Channel Integrationon the Integrations page. Please follow this document to add an integration.

Currently two types of Notification Channels are supported:

  1. Slack (Webhook URL based): For this, please create a webhook for your slack and then add it as an integration in Slack Provider Account
  2. Email (SMTP credentials Integration): This can be found in Custom Provider Account. You can configure the SMTP Credentials of the mail server, from_email and to_emails and use it to send notifications.

How to Configure

Define alerts in workflow Decorator

  • You can define or configure the alerts in the workflow decorator in your workflow file.
from truefoundry.workflow import ...
from truefoundry.deploy import Resources, WorkflowAlert, Email, SlackWebhook

...
...
@workflow(
    alerts=[
        WorkflowAlert(
            notification_target=Email(
                notification_channel="<Paste your email notification integration fqn here>",
                to_emails=[
                    "demo@truefoundry.com"
                ],
            ),
            on_completion=True,
            on_failure=True,
        ),
        WorkflowAlert(
            notification_target=SlackWebhook(
                notification_channel="<Paste your slack webhook notification integration fqn here>",
            ),
            on_completion=True,
            on_failure=True,
        ),
    ]
)
def my_wofklow():
	...

⚠️

Make sure that the truefoundry package version is set to latest version in task config.

For example in pip_packages filed in python task config, make sure that trufoundry[workflow] version is 0.6.3 or newer and not older one, or make sure that version which you are mentioning supports alerts.

  • Right now the alert notification is supported only for workflow completion(successful completio and workflow failure(failure includes failed executions and aborted as well as timed out workflow executions).
  • There are two types of targets, one is email and the other is slack webhook, you need to add an email integration or slack webhook respectively and select it in notification channel field to use that integration for sending notifiactions.
  • Now when you will deploy the workflow, the alerts will be set.

Define alerts in deploy.py file

  • Another way to define alerts is to define workflow in deploy.py file and set alerts in it.
from truefoundry.deploy import Workflow, WorkflowAlert, SlackWebhook, Email


wf = Workflow(
    name="test-email-alerts-2",
    workflow_file_path="nested.py",
    alerts=[
        WorkflowAlert(
            notification_target=SlackWebhook(
                notification_channel="<Paste your slack webhook notification integration fqn here>",
            ),
            on_completion=True,
            on_failure=True,
        ),
        WorkflowAlert(
            notification_target=Email(
                notification_channel="<Paste your email notification integration fqn here>",
                to_emails=["demo@truefoundry.com"],
            ),
            on_completion=True,
            on_failure=True,
        ),
    ],
)

wf.deploy("<workspace-fqn>", wait=False)
  • After defining this, you can just run python deploy.py and your workflow will be deployed and alerts will be set.