Notifications

When a workflow completes, users can be notified by:

The content of these notifications is configurable at the platform level.

Usage

When a workflow reaches a specified terminal workflow execution phase the flytekit.Email, flytekit.PagerDuty, or flytekit.Slack objects can be used in the construction of a flytekit.LaunchPlan.

For example

from flytekit import Email, LaunchPlan
from flytekit.models.core.execution import WorkflowExecutionPhase

# This launch plan triggers email notifications when the workflow execution it triggered reaches the phase `SUCCEEDED`.
my_notifiying_lp = LaunchPlan.create(
    "my_notifiying_lp",
    my_workflow_definition,
    default_inputs={"a": 4},
    notifications=[
        Email(
            phases=[WorkflowExecutionPhase.SUCCEEDED],
            recipients_email=["admin@example.com"],
        )
    ],
)

See detailed usage examples in the User Guide

Notifications can be combined with schedules to automatically alert you when a scheduled job succeeds or fails.

Future work

Work is ongoing to support a generic event egress system that can be used to publish events for tasks, workflows and workflow nodes. When this is complete, generic event subscribers can asynchronously process these vents for a rich and fully customizable experience.

Platform Configuration Changes

Setting Up Workflow Notifications

The notifications top-level portion of the FlyteAdmin config specifies how to handle notifications.

As with schedules, the notifications handling is composed of two parts. One handles enqueuing notifications asynchronously and the second part handles processing pending notifications and actually firing off emails and alerts.

This is only supported for Flyte instances running on AWS.

Config

To publish notifications, you’ll need to set up an SNS topic.

In order to process notifications, you’ll need to set up an AWS SQS queue to consume notification events. This queue must be configured as a subscription to your SNS topic you created above.

In order to actually publish notifications, you’ll need a verified SES email address which will be used to send notification emails and alerts using email APIs.

The role you use to run FlyteAdmin must have permissions to read and write to your SNS topic and SQS queue.

Let’s look at the following config section and explain what each value represents:

notifications:
  type: "aws"
  region: "us-east-1"
  publisher:
    topicName: "arn:aws:sns:us-east-1:{{ YOUR ACCOUNT ID }}:{{ YOUR TOPIC }}"
  processor:
    queueName: "{{ YOUR QUEUE NAME }}"
    accountId: "{{ YOUR ACCOUNT ID }}"
  emailer:
    subject: "Notice: Execution \"{{ workflow.name }}\" has {{ phase }} in \"{{ domain }}\"."
    sender:  "flyte-notifications@company.com"
    body: >
      Execution \"{{ workflow.name }} [{{ name }}]\" has {{ phase }} in \"{{ domain }}\". View details at
      <a href=\http://flyte.company.com/console/projects/{{ project }}/domains/{{ domain }}/executions/{{ name }}>
      http://flyte.company.com/console/projects/{{ project }}/domains/{{ domain }}/executions/{{ name }}</a>. {{ error }}
  • type: Because AWS is the only cloud back-end supported for executing scheduled workflows in this case, only "aws" is a valid value. By default, the no-op executor is used.

  • region: This specifies which region AWS clients will use when creating SNS and SQS clients.

  • publisher: This handles pushing notification events to your SNS topic.
    • topicName: This is the arn of your SNS topic.

  • processor: This handles the recording notification events and enqueueing them to be processed asynchronously.
    • queueName: This is the name of the SQS queue which will capture pending notification events.

    • accountId: Your AWS account id

  • emailer: This section encloses config details for sending and formatting emails used as notifications.
    • subject: Configurable subject line used in notification emails.

    • sender: Your verified SES email sender.

    • body: Configurable email body used in notifications.

The full set of parameters which can be used for email templating are checked into code.

Example config

  host: localhost
  dbname: postgres
  options: "sslmode=disable"
scheduler:
  eventScheduler:
    scheme: local
    region: "my-region"
    scheduleRole: "arn:aws:iam::abc123:role/my-iam-role"
    targetName: "arn:aws:sqs:my-region:abc123:my-queue"
    scheduleNamePrefix: "flyte"
  workflowExecutor:
    scheme: local
    local:
      adminRateLimit:
        tps: 100 # per sec how many requests to send to admin