o-nikolas commented on code in PR #36550:
URL: https://github.com/apache/airflow/pull/36550#discussion_r1443400326


##########
airflow/providers/amazon/aws/sensors/redshift_cluster.py:
##########
@@ -66,6 +72,38 @@ def poke(self, context: Context):
         )
         return current_status == self.target_status
 
+    def execute(self, context: Context) -> None:
+        if not self.deferrable:
+            super().execute(context=context)
+        elif not self.poke(context):
+            self.defer(
+                timeout=timedelta(seconds=self.timeout),
+                trigger=RedshiftClusterSensorTrigger(
+                    aws_conn_id=self.aws_conn_id,
+                    cluster_identifier=self.cluster_identifier,
+                    target_status=self.target_status,
+                    poke_interval=self.poke_interval,
+                ),
+                method_name="execute_complete",
+            )
+
+    def execute_complete(self, context: Context, event: dict[str, Any] | None 
= None) -> None:
+        if event is None:
+            err_msg = "Trigger error: event is None"
+            self.log.info(err_msg)

Review Comment:
   Error (or at least warning) level for this log message?



##########
tests/providers/amazon/aws/triggers/test_redshift_cluster.py:
##########
@@ -0,0 +1,125 @@
+# 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 unittest import mock
+
+import pytest
+
+from airflow.providers.amazon.aws.triggers.redshift_cluster import (
+    RedshiftClusterSensorTrigger,
+)
+from airflow.triggers.base import TriggerEvent
+
+POLLING_PERIOD_SECONDS = 1.0
+
+
+class TestRedshiftClusterSensorTrigger:
+    def test_redshift_cluster_sensor_trigger_serialization(self):
+        """
+        Asserts that the RedshiftClusterSensorTrigger correctly serializes its 
arguments
+        and classpath.
+        """
+        trigger = RedshiftClusterSensorTrigger(
+            aws_conn_id="test_redshift_conn_id",
+            cluster_identifier="mock_cluster_identifier",
+            target_status="available",
+            poke_interval=POLLING_PERIOD_SECONDS,
+        )
+        classpath, kwargs = trigger.serialize()
+        assert (
+            classpath == 
"airflow.providers.amazon.aws.triggers.redshift_cluster.RedshiftClusterSensorTrigger"
+        )
+        assert kwargs == {
+            "aws_conn_id": "test_redshift_conn_id",
+            "cluster_identifier": "mock_cluster_identifier",
+            "target_status": "available",
+            "poke_interval": POLLING_PERIOD_SECONDS,
+        }
+
+    @pytest.mark.asyncio
+    @pytest.mark.parametrize(
+        "expected_result",
+        [
+            ({"status": "success", "cluster_state": "available"}),

Review Comment:
   parameterizing with just one set of params?



-- 
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: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to