Source code for airflow.providers.amazon.aws.triggers.redshift_cluster
# 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__importannotationsfromtypingimportAny,AsyncIteratorfromairflow.compat.functoolsimportcached_propertyfromairflow.providers.amazon.aws.hooks.redshift_clusterimportRedshiftAsyncHook,RedshiftHookfromairflow.triggers.baseimportBaseTrigger,TriggerEvent
[docs]asyncdefrun(self)->AsyncIterator[TriggerEvent]:hook=RedshiftAsyncHook(aws_conn_id=self.aws_conn_id)whileself.attempts>=1:self.attempts=self.attempts-1try:ifself.operation_type=="pause_cluster":response=awaithook.pause_cluster(cluster_identifier=self.cluster_identifier,poll_interval=self.poll_interval,)ifresponse.get("status")=="success":yieldTriggerEvent(response)else:ifself.attempts<1:yieldTriggerEvent({"status":"error","message":f"{self.task_id} failed"})elifself.operation_type=="resume_cluster":response=awaithook.resume_cluster(cluster_identifier=self.cluster_identifier,polling_period_seconds=self.poll_interval,)ifresponse:yieldTriggerEvent(response)else:error_message=f"{self.task_id} failed"yieldTriggerEvent({"status":"error","message":error_message})else:yieldTriggerEvent(f"{self.operation_type} is not supported")exceptExceptionase:ifself.attempts<1:yieldTriggerEvent({"status":"error","message":str(e)})
[docs]classRedshiftCreateClusterTrigger(BaseTrigger):""" Trigger for RedshiftCreateClusterOperator. The trigger will asynchronously poll the boto3 API and wait for the Redshift cluster 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_identifierself.poll_interval=poll_intervalself.max_attempt=max_attemptself.aws_conn_id=aws_conn_id