Skip to main content

Decorator to send alert when a Prefect task or flow fails

Project description

prefect-alert

PyPI

Welcome!

Prefect is an open-source library that allows you to orchestrate and observe your dataflow defined in Python.

prefect-alert is a decorator that allows you to send alert when a Prefect flow fails.

Read this article if you are not familiar with how to send notifications with Prefect.

Getting Started

Python setup

Requires an installation of Python 3.8+.

We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.

The decorator is designed to work with Prefect 2.0. For more information about how to use Prefect, please refer to the Prefect documentation.

Installation

Install prefect-alert with pip:

pip install prefect-alert

Create a notification block

Blocks enable you to store configuration and provide an interface for interacting with external systems.

First, start with creating a notification block through UI or a Python script:

from prefect.blocks.notifications import SlackWebhook

slack_block = SlackWebhook(url="https://hooks.slack.com/services/XXX/XXX/XXX")

Send an alert

Next, use the block created and the decorator prefect_alert.alert_on_failure to send alert when a flow fails.

Send an alert when a flow fails

from prefect import flow, task 
from prefect.blocks.notifications import SlackWebhook
from prefect_alert import alert_on_failure

@task
def may_fail():
    raise ValueError()

@alert_on_failure(block_type=SlackWebhook, block_name="test")
@flow
def failed_flow():
    res = may_fail()
    return res

if __name__=="__main__":
    failed_flow()

And you will see something like this on your Slack:

Send an alert when a asynchronous flow fails

from prefect import flow, task 
from prefect.blocks.notifications import SlackWebhook
from prefect_alert import alert_on_failure
import asyncio

@task
async def may_fail():
    raise ValueError()

@alert_on_failure(block_type=SlackWebhook, block_name="test")
@flow
async def failed_flow():
    res = await may_fail()
    return res

if __name__=="__main__":
    asyncio.run(failed_flow())

Resources

If you encounter any bugs while using prefect-alert, feel free to open an issue in the prefect-alert repository.

If you have any questions or issues while using prefect-alert, you can find help in either the Prefect Discourse forum or the Prefect Slack community.

Feel free to ⭐️ or watch prefect-alert for updates too!

Development

If you'd like to install a version of prefect-alert for development, clone the repository and perform an editable install with pip:

git clone https://github.com/khuyentran1401/prefect-alert.git

cd prefect-alert/

pip install -e ".[dev]"

# Install linting pre-commit hooks
pre-commit install

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prefect-alert-0.1.3.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prefect_alert-0.1.3-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file prefect-alert-0.1.3.tar.gz.

File metadata

  • Download URL: prefect-alert-0.1.3.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for prefect-alert-0.1.3.tar.gz
Algorithm Hash digest
SHA256 c79dd5e353fd79253253b5aa78f05fb0b16baf56844fb534a452bd2c03ee98a9
MD5 54212c5d1209395cd1389e853d3902ac
BLAKE2b-256 1bad1b1d045e6ad3d68e8ea4d0bf2a06d8c440d6d1d02175d2b6bee54420c3ee

See more details on using hashes here.

File details

Details for the file prefect_alert-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: prefect_alert-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.15

File hashes

Hashes for prefect_alert-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 4d248a97ffd52a66e21d4afc112687d492a01057a8efbf2a2b94dda00e30c297
MD5 a6718420cf0755964a7ccce9f1c7182e
BLAKE2b-256 73c075f6785cb8e578517ff253a47d2942369bea69ba80695a693e850897c2d6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page