Lee-W commented on code in PR #32809:
URL: https://github.com/apache/airflow/pull/32809#discussion_r1280049380


##########
airflow/providers/amazon/aws/triggers/sqs.py:
##########
@@ -0,0 +1,171 @@
+# 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.
+from __future__ import annotations
+
+import asyncio
+from typing import Any, Collection, Literal
+
+from airflow.exceptions import AirflowException
+from airflow.providers.amazon.aws.hooks.base_aws import BaseAwsConnection
+from airflow.providers.amazon.aws.hooks.sqs import SqsHook
+from airflow.providers.amazon.aws.utils.sqs import process_response
+from airflow.triggers.base import BaseTrigger, TriggerEvent
+
+
+class SqsSensorTrigger(BaseTrigger):
+    """
+    Asynchronously get messages from an Amazon SQS queue and then delete the 
messages from the queue.
+
+    :param aws_conn_id: AWS connection id
+    :param sqs_queue: The SQS queue url
+    :param max_messages: The maximum number of messages to retrieve for each 
poke (templated)
+    :param num_batches: The number of times the sensor will call the SQS API 
to receive messages (default: 1)
+    :param wait_time_seconds: The time in seconds to wait for receiving 
messages (default: 1 second)
+    :param visibility_timeout: Visibility timeout, a period of time during 
which
+        Amazon SQS prevents other consumers from receiving and processing the 
message.
+    :param message_filtering: Specified how received messages should be 
filtered. Supported options are:
+        `None` (no filtering, default), `'literal'` (message Body literal 
match) or `'jsonpath'`
+        (message Body filtered using a JSONPath expression).
+        You may add further methods by overriding the relevant class methods.
+    :param message_filtering_match_values: Optional value/s for the message 
filter to match on.
+        For example, with literal matching, if a message body matches any of 
the specified values
+        then it is included. For JSONPath matching, the result of the JSONPath 
expression is used
+        and may match any of the specified values.
+    :param message_filtering_config: Additional configuration to pass to the 
message filter.
+        For example with JSONPath filtering you can pass a JSONPath expression 
string here,
+        such as `'foo[*].baz'`. Messages with a Body which does not match are 
ignored.
+    :param delete_message_on_reception: Default to `True`, the messages are 
deleted from the queue
+        as soon as being consumed. Otherwise, the messages remain in the queue 
after consumption and
+        should be deleted manually.
+    :param waiter_delay: The time in seconds to wait between calls to the SQS 
API to receive messages.
+    """
+
+    def __init__(
+        self,
+        sqs_queue,
+        aws_conn_id: str = "aws_default",
+        max_messages: int = 5,
+        num_batches: int = 1,
+        wait_time_seconds: int = 1,
+        visibility_timeout: int | None = None,
+        message_filtering: Literal["literal", "jsonpath"] | None = None,
+        message_filtering_match_values: Any = None,
+        message_filtering_config: Any = None,

Review Comment:
   Got it. Sounds good 👍



##########
airflow/providers/amazon/aws/triggers/sqs.py:
##########
@@ -0,0 +1,171 @@
+# 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.
+from __future__ import annotations
+
+import asyncio
+from typing import Any, Collection, Literal
+
+from airflow.exceptions import AirflowException
+from airflow.providers.amazon.aws.hooks.base_aws import BaseAwsConnection
+from airflow.providers.amazon.aws.hooks.sqs import SqsHook
+from airflow.providers.amazon.aws.utils.sqs import process_response
+from airflow.triggers.base import BaseTrigger, TriggerEvent
+
+
+class SqsSensorTrigger(BaseTrigger):
+    """
+    Asynchronously get messages from an Amazon SQS queue and then delete the 
messages from the queue.
+
+    :param aws_conn_id: AWS connection id
+    :param sqs_queue: The SQS queue url
+    :param max_messages: The maximum number of messages to retrieve for each 
poke (templated)
+    :param num_batches: The number of times the sensor will call the SQS API 
to receive messages (default: 1)
+    :param wait_time_seconds: The time in seconds to wait for receiving 
messages (default: 1 second)
+    :param visibility_timeout: Visibility timeout, a period of time during 
which
+        Amazon SQS prevents other consumers from receiving and processing the 
message.
+    :param message_filtering: Specified how received messages should be 
filtered. Supported options are:
+        `None` (no filtering, default), `'literal'` (message Body literal 
match) or `'jsonpath'`
+        (message Body filtered using a JSONPath expression).
+        You may add further methods by overriding the relevant class methods.
+    :param message_filtering_match_values: Optional value/s for the message 
filter to match on.
+        For example, with literal matching, if a message body matches any of 
the specified values
+        then it is included. For JSONPath matching, the result of the JSONPath 
expression is used
+        and may match any of the specified values.
+    :param message_filtering_config: Additional configuration to pass to the 
message filter.
+        For example with JSONPath filtering you can pass a JSONPath expression 
string here,
+        such as `'foo[*].baz'`. Messages with a Body which does not match are 
ignored.
+    :param delete_message_on_reception: Default to `True`, the messages are 
deleted from the queue
+        as soon as being consumed. Otherwise, the messages remain in the queue 
after consumption and
+        should be deleted manually.
+    :param waiter_delay: The time in seconds to wait between calls to the SQS 
API to receive messages.
+    """
+
+    def __init__(
+        self,
+        sqs_queue,
+        aws_conn_id: str = "aws_default",
+        max_messages: int = 5,
+        num_batches: int = 1,
+        wait_time_seconds: int = 1,
+        visibility_timeout: int | None = None,
+        message_filtering: Literal["literal", "jsonpath"] | None = None,
+        message_filtering_match_values: Any = None,
+        message_filtering_config: Any = None,

Review Comment:
   Got it. Sounds good 👍



-- 
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]

Reply via email to