You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "vincbeck (via GitHub)" <gi...@apache.org> on 2023/05/01 15:50:03 UTC

[GitHub] [airflow] vincbeck commented on a diff in pull request #30856: Add Deferrable Mode to RedshiftCreateClusterSnapshotOperator

vincbeck commented on code in PR #30856:
URL: https://github.com/apache/airflow/pull/30856#discussion_r1181672688


##########
airflow/providers/amazon/aws/triggers/redshift_cluster.py:
##########
@@ -137,3 +137,51 @@ async def run(self):
                 },
             )
         yield TriggerEvent({"status": "success", "message": "Cluster Created"})
+
+
+class RedshiftCreateClusterSnapshotTrigger(BaseTrigger):
+    """
+    Trigger for RedshiftCreateClusterSnapshotOperator.
+    The trigger will asynchronously poll the boto3 API and wait for the
+    Redshift cluster snapshot to be in the `available` state.
+
+    :param cluster_identifier:  A unique identifier for the cluster.
+    :param poll_interval: The amount of time in seconds to wait between attempts.
+    :param max_attempt: The maximum number of attempts to be made.
+    :param aws_conn_id: The Airflow connection used for AWS credentials.
+    """
+
+    def __init__(
+        self,
+        cluster_identifier: str,
+        poll_interval: int,
+        max_attempt: int,
+        aws_conn_id: str,
+    ):
+        self.cluster_identifier = cluster_identifier
+        self.poll_interval = poll_interval
+        self.max_attempt = max_attempt
+        self.aws_conn_id = aws_conn_id
+
+    def serialize(self) -> tuple[str, dict[str, Any]]:
+        return (
+            "airflow.providers.amazon.aws.triggers.redshift_cluster.RedshiftCreateClusterSnapshotTrigger",
+            {
+                "cluster_identifier": str(self.cluster_identifier),
+                "poll_interval": str(self.poll_interval),
+                "max_attempt": str(self.max_attempt),
+                "aws_conn_id": str(self.aws_conn_id),
+            },
+        )
+
+    async def run(self):
+        self.redshift_hook = RedshiftHook(aws_conn_id=self.aws_conn_id)

Review Comment:
   nit. Use `@cached_property` to create the hook? 



-- 
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-unsubscribe@airflow.apache.org

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