Skip to content

Conversation

@dondaum
Copy link
Contributor

@dondaum dondaum commented Oct 15, 2025

Add an asynchronous version of SlackNotifier.

related: #55237

I've added a backwards compatible way to get an Airflow connection using an asynchronous call. In my opinion it was not compatible with before all airflows <3.0.0, which was also confirmed by the CI tests.

Also, I removed @functools.cached_property from an asynchronous method in SlackWebhookHook. In my opinion you can't use @functools.cached_property directly with asynchronous methods because asynchronous methods return Coroutine objects instead of actual values.

I sucessfully tested the SlackNotifier with the following Dag:

from datetime import timedelta
from airflow import DAG
from airflow.sdk.definitions.deadline import AsyncCallback, DeadlineAlert, DeadlineReference
from airflow.providers.slack.notifications.slack import SlackNotifier
from airflow.providers.standard.operators.empty import EmptyOperator
from airflow.sdk import task

with DAG(
    dag_id="deadline_slack_alert_example",
    deadline=DeadlineAlert(
        reference=DeadlineReference.DAGRUN_QUEUED_AT,
        interval=timedelta(seconds=20),
        callback=AsyncCallback(
            SlackNotifier,
            kwargs={
                "text": "🚨 Dag {{ dag_run.dag_id }} missed deadline at {{ deadline.deadline_time }}. DagRun: {{ dag_run }}",
                "channel": "#allgemein",
                "username": "Test App",
            },
        ),
    ),
):
    c = EmptyOperator(task_id="example_task")

    @task()
    def wait():
        import time
        time.sleep(60*5)

    
    c >> wait()
Screenshot 2025-10-15 224828 Screenshot 2025-10-15 224858

^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@dondaum dondaum requested a review from eladkal as a code owner October 15, 2025 20:53
@dondaum dondaum force-pushed the feat/async-slack-notifier branch 2 times, most recently from 916782c to c2f6c0f Compare October 16, 2025 08:11
@dondaum dondaum changed the title feat: async slack notifier [WIP] feat: async slack notifier Oct 16, 2025
@dondaum dondaum force-pushed the feat/async-slack-notifier branch from c2f6c0f to 24c1a4f Compare October 16, 2025 09:49
@dondaum dondaum changed the title [WIP] feat: async slack notifier feat: async slack notifier Oct 16, 2025
@ferruzzi ferruzzi mentioned this pull request Oct 16, 2025
1 task
@ferruzzi
Copy link
Contributor

Also, I removed @functools.cached_property from an asynchronous method in SlackWebhookHook. In my opinion you can't use @functools.cached_property directly with asynchronous methods because asynchronous methods return Coroutine objects instead of actual values

Interesting. Good catch.

Copy link
Contributor

@shahar1 shahar1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@shahar1 shahar1 merged commit 1ba8c1d into apache:main Oct 17, 2025
92 checks passed
abdulrahman305 bot pushed a commit to abdulrahman305/airflow that referenced this pull request Oct 19, 2025
TyrellHaywood pushed a commit to TyrellHaywood/airflow that referenced this pull request Oct 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants