Source code for airflow.providers.amazon.aws.sensors.ecs
# 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__importannotationsfromcollections.abcimportSequencefromfunctoolsimportcached_propertyfromtypingimportTYPE_CHECKINGfromairflow.exceptionsimportAirflowExceptionfromairflow.providers.amazon.aws.hooks.ecsimport(EcsClusterStates,EcsHook,EcsTaskDefinitionStates,EcsTaskStates,)fromairflow.providers.amazon.aws.sensors.base_awsimportAwsBaseSensorfromairflow.providers.amazon.aws.utils.mixinsimportaws_template_fieldsifTYPE_CHECKING:importboto3fromairflow.utils.contextimportContextdef_check_failed(current_state,target_state,failure_states)->None:if(current_state!=target_state)and(current_stateinfailure_states):raiseAirflowException(f"Terminal state reached. Current state: {current_state}, Expected state: {target_state}")
[docs]classEcsBaseSensor(AwsBaseSensor[EcsHook]):"""Contains general sensor behavior for Elastic Container Service."""
[docs]defclient(self)->boto3.client:"""Create and return an EcsHook client."""returnself.hook.conn
[docs]classEcsClusterStateSensor(EcsBaseSensor):""" Poll the cluster state until it reaches a terminal state; raises AirflowException with the failure reason. .. seealso:: For more information on how to use this operator, take a look at the guide: :ref:`howto/sensor:EcsClusterStateSensor` :param cluster_name: The name of your cluster. :param target_state: Success state to watch for. (Default: "ACTIVE") :param failure_states: Fail if any of these states are reached before the Success State. (Default: "FAILED" or "INACTIVE") """
[docs]classEcsTaskDefinitionStateSensor(EcsBaseSensor):""" Poll task definition until it reaches a terminal state; raise AirflowException with the failure reason. .. seealso:: For more information on how to use this operator, take a look at the guide: :ref:`howto/sensor:EcsTaskDefinitionStateSensor` :param task_definition: The family for the latest ACTIVE revision, family and revision (family:revision ) for a specific revision in the family, or full Amazon Resource Name (ARN) of the task definition. :param target_state: Success state to watch for. (Default: "ACTIVE") """
[docs]classEcsTaskStateSensor(EcsBaseSensor):""" Poll the task state until it reaches a terminal state; raises AirflowException with the failure reason. .. seealso:: For more information on how to use this operator, take a look at the guide: :ref:`howto/sensor:EcsTaskStateSensor` :param cluster: The short name or full Amazon Resource Name (ARN) of the cluster that hosts the task. :param task: The task ID or full ARN of the task to poll. :param target_state: Success state to watch for. (Default: "ACTIVE") :param failure_states: Fail if any of these states are reached before the Success State. (Default: "STOPPED") """