ferruzzi opened a new pull request, #56159:
URL: https://github.com/apache/airflow/pull/56159
Adds async support to the existing SQS Notifier so it can be used as an
AsyncCallback for DeadlineAlerts, among other things
dags used for manual testing:
```python
from datetime import datetime, timedelta
from airflow.providers.amazon.aws.hooks.sqs import SqsHook
from airflow.providers.amazon.aws.notifications.sqs import SqsNotifier
from airflow.sdk import task, DAG
from airflow.sdk.definitions.deadline import DeadlineAlert,
DeadlineReference, AsyncCallback
PAST_DATE = datetime(1980, 8, 10, 2)
MSG_PREFIX = "SQS Testing Rnd 0:"
DEFAULTS = {"queue_url":
"https://sqs.us-east-1.amazonaws.com/324969868898/async-notifier-testing"}
def _sqs_callback(context):
SqsHook().send_message(**DEFAULTS, message_body=f"{MSG_PREFIX} Hook as
Callback -- {context['dag_run'].dag_id}")
@task
def send_sqs_message(message):
SqsHook().send_message(**DEFAULTS, message_body=message)
@task.bash(task_id='sleep_task')
def sleep_n_secs(seconds):
return f'sleep {seconds}'
with DAG(
"sqs_hook_via_taskflow",
tags=["sqs"]
):
send_sqs_message(message=f"{MSG_PREFIX} Taskflow -- {{{{ dag_run.dag_id
}}}} ")
with DAG(
"sqs_callback_on_success",
on_success_callback=_sqs_callback,
tags=["sqs"],
):
sleep_n_secs(1)
with DAG(
"sqs_notifier_as_callback",
on_success_callback=SqsNotifier(**DEFAULTS, message_body=f"{MSG_PREFIX}
Sync Notifier as callback -- {{{{ dag_run.dag_id }}}} "),
tags=["sqs"],
):
sleep_n_secs(1)
with DAG(
"sqs_notifier_as_deadline",
deadline=DeadlineAlert(
reference=DeadlineReference.FIXED_DATETIME(PAST_DATE),
interval=timedelta(0),
callback=AsyncCallback(
SqsNotifier,
kwargs={**DEFAULTS, "message_body": f"{MSG_PREFIX} Async
Notifier as Deadline -- {{{{ dag_run.dag_id }}}} "}
),
),
tags=["sqs"],
):
sleep_n_secs(1)
```
and proof of delivery with intact templating:
<img width="1087" height="255" alt="image"
src="https://github.com/user-attachments/assets/e0c3a5f4-808e-403e-90bb-ba0032e46458"
/>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<!--
Thank you for contributing! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.
Feel free to ping committers for the review!
In case of an existing issue, reference it using one of the following:
closes: #ISSUE
related: #ISSUE
How to write a good git commit message:
http://chris.beams.io/posts/git-commit/
-->
<!-- Please keep an empty line above the dashes. -->
---
**^ Add meaningful description above**
Read the **[Pull Request
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
for more information.
In case of fundamental code changes, an Airflow Improvement Proposal
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
is needed.
In case of a new dependency, check compliance with the [ASF 3rd Party
License Policy](https://www.apache.org/legal/resolved.html#category-x).
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](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]