class_docstr: Execute a task on AWS ECS (Elastic Container Service).
  
  .. seealso::
      For more information on how to use this operator, take a look at the guide:
      :ref:`howto/operator:EcsRunTaskOperator`
  
  :param task_definition: the task definition name on Elastic Container Service
  :param cluster: the cluster name on Elastic Container Service
  :param overrides: the same parameter that boto3 will receive (templated):
      https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ecs.html#ECS.Client.run_task
  :param aws_conn_id: connection id of AWS credentials / region name. If None,
      credential boto3 strategy will be used
      (https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuration.html).
  :param region: region name to use in AWS Hook.
      Override the region in connection (if provided)
  :param launch_type: the launch type on which to run your task ('EC2', 'EXTERNAL', or 'FARGATE')
  :param capacity_provider_strategy: the capacity provider strategy to use for the task.
      When capacity_provider_strategy is specified, the launch_type parameter is omitted.
      If no capacity_provider_strategy or launch_type is specified,
      the default capacity provider strategy for the cluster is used.
  :param group: the name of the task group associated with the task
  :param placement_constraints: an array of placement constraint objects to use for
      the task
  :param placement_strategy: an array of placement strategy objects to use for
      the task
  :param platform_version: the platform version on which your task is running
  :param network_configuration: the network configuration for the task
  :param tags: a dictionary of tags in the form of {'tagKey': 'tagValue'}.
  :param awslogs_group: the CloudWatch group where your ECS container logs are stored.
      Only required if you want logs to be shown in the Airflow UI after your job has
      finished.
  :param awslogs_region: the region in which your CloudWatch logs are stored.
      If None, this is the same as the `region` parameter. If that is also None,
      this is the default AWS region based on your connection settings.
  :param awslogs_stream_prefix: the stream prefix that is used for the CloudWatch logs.
      This is usually based on some custom name combined with the name of the container.
      Only required if you want logs to be shown in the Airflow UI after your job has
      finished.
  :param awslogs_fetch_interval: the interval that the ECS task log fetcher should wait
      in between each Cloudwatch logs fetches.
      If deferrable is set to True, that parameter is ignored and waiter_delay is used instead.
  :param quota_retry: Config if and how to retry the launch of a new ECS task, to handle
      transient errors.
  :param reattach: If set to True, will check if the task previously launched by the task_instance
      is already running. If so, the operator will attach to it instead of starting a new task.
      This is to avoid relaunching a new task when the connection drops between Airflow and ECS while
      the task is running (when the Airflow worker is restarted for example).
  :param number_logs_exception: Number of lines from the last Cloudwatch logs to return in the
      AirflowException if an ECS task is stopped (to receive Airflow alerts with the logs of what
      failed in the code running in ECS).
  :param wait_for_completion: If True, waits for creation of the cluster to complete. (default: True)
  :param waiter_delay: The amount of time in seconds to wait between attempts,
      if not set then the default waiter value will be used.
  :param waiter_max_attempts: The maximum number of attempts to be made,
      if not set then the default waiter value will be used.
  :param deferrable: If True, the operator will wait asynchronously for the job to complete.
      This implies waiting for completion. This mode requires aiobotocore module to be installed.
      (default: False)
class_docstr_tok: ["Execute","a","task","on","AWS","ECS","(","Elastic","Container","Service",")",".","..","seealso",":",":","For","more","information","on","how","to","use","this","operator",",","take","a","look","at","the","guide",":",":","ref",":","`","howto\/operator",":","EcsRunTaskOperator","`",":","param","task_definition",":","the","task","definition","name","on","Elastic","Container","Service",":","param","cluster",":","the","cluster","name","on","Elastic","Container","Service",":","param","overrides",":","the","same","parameter","that","boto3","will","receive","(","templated",")",":","https",":","\/\/boto3.amazonaws.com\/v1\/documentation\/api\/latest\/reference\/services\/ecs.html","#","ECS.Client.run_task",":","param","aws_conn_id",":","connection","id","of","AWS","credentials","\/","region","name",".","If","None",",","credential","boto3","strategy","will","be","used","(","https",":","\/\/boto3.amazonaws.com\/v1\/documentation\/api\/latest\/guide\/configuration.html",")",".",":","param","region",":","region","name","to","use","in","AWS","Hook",".","Override","the","region","in","connection","(","if","provided",")",":","param","launch_type",":","the","launch","type","on","which","to","run","your","task","(","'EC2","'",",","'EXTERNAL","'",",","or","'FARGATE","'",")",":","param","capacity_provider_strategy",":","the","capacity","provider","strategy","to","use","for","the","task",".","When","capacity_provider_strategy","is","specified",",","the","launch_type","parameter","is","omitted",".","If","no","capacity_provider_strategy","or","launch_type","is","specified",",","the","default","capacity","provider","strategy","for","the","cluster","is","used",".",":","param","group",":","the","name","of","the","task","group","associated","with","the","task",":","param","placement_constraints",":","an","array","of","placement","constraint","objects","to","use","for","the","task",":","param","placement_strategy",":","an","array","of","placement","strategy","objects","to","use","for","the","task",":","param","platform_version",":","the","platform","version","on","which","your","task","is","running",":","param","network_configuration",":","the","network","configuration","for","the","task",":","param","tags",":","a","dictionary","of","tags","in","the","form","of","{","'tagKey","'",":","'tagValue","'","}",".",":","param","awslogs_group",":","the","CloudWatch","group","where","your","ECS","container","logs","are","stored",".","Only","required","if","you","want","logs","to","be","shown","in","the","Airflow","UI","after","your","job","has","finished",".",":","param","awslogs_region",":","the","region","in","which","your","CloudWatch","logs","are","stored",".","If","None",",","this","is","the","same","as","the","`","region","`","parameter",".","If","that","is","also","None",",","this","is","the","default","AWS","region","based","on","your","connection","settings",".",":","param","awslogs_stream_prefix",":","the","stream","prefix","that","is","used","for","the","CloudWatch","logs",".","This","is","usually","based","on","some","custom","name","combined","with","the","name","of","the","container",".","Only","required","if","you","want","logs","to","be","shown","in","the","Airflow","UI","after","your","job","has","finished",".",":","param","awslogs_fetch_interval",":","the","interval","that","the","ECS","task","log","fetcher","should","wait","in","between","each","Cloudwatch","logs","fetches",".","If","deferrable","is","set","to","True",",","that","parameter","is","ignored","and","waiter_delay","is","used","instead",".",":","param","quota_retry",":","Config","if","and","how","to","retry","the","launch","of","a","new","ECS","task",",","to","handle","transient","errors",".",":","param","reattach",":","If","set","to","True",",","will","check","if","the","task","previously","launched","by","the","task_instance","is","already","running",".","If","so",",","the","operator","will","attach","to","it","instead","of","starting","a","new","task",".","This","is","to","avoid","relaunching","a","new","task","when","the","connection","drops","between","Airflow","and","ECS","while","the","task","is","running","(","when","the","Airflow","worker","is","restarted","for","example",")",".",":","param","number_logs_exception",":","Number","of","lines","from","the","last","Cloudwatch","logs","to","return","in","the","AirflowException","if","an","ECS","task","is","stopped","(","to","receive","Airflow","alerts","with","the","logs","of","what","failed","in","the","code","running","in","ECS",")",".",":","param","wait_for_completion",":","If","True",",","waits","for","creation","of","the","cluster","to","complete",".","(","default",":","True",")",":","param","waiter_delay",":","The","amount","of","time","in","seconds","to","wait","between","attempts",",","if","not","set","then","the","default","waiter","value","will","be","used",".",":","param","waiter_max_attempts",":","The","maximum","number","of","attempts","to","be","made",",","if","not","set","then","the","default","waiter","value","will","be","used",".",":","param","deferrable",":","If","True",",","the","operator","will","wait","asynchronously","for","the","job","to","complete",".","This","implies","waiting","for","completion",".","This","mode","requires","aiobotocore","module","to","be","installed",".","(","default",":","False",")"]
code: def _check_success_task(self) -> None:
      if not self.client or not self.arn:
          return
  
      response = self.client.describe_tasks(
          cluster=self.cluster, tasks=[self.arn]
      )
      self.log.info("ECS Task stopped, check status: %s", response)
  
      if len(response.get("failures", [])) > 0:
          raise AirflowException(response)
  
      for task in response["tasks"]:
          if task.get("stopCode", "") == "TaskFailedToStart":
              # Reset task arn here otherwise the retry run will not start
              # a new task but keep polling the old dead one
              # I'm not resetting it for other exceptions here because
              # EcsTaskFailToStart is the only exception that's being retried at the moment
              self.arn = None
              raise EcsTaskFailToStart(
                  f"The task failed to start due to: {task.get('stoppedReason', '')}"
              )
  
          # This is a `stoppedReason` that indicates a task has not
          # successfully finished, but there is no other indication of failure
          # in the response.
          # https://docs.aws.amazon.com/AmazonECS/latest/developerguide/stopped-task-errors.html
          if re.match(
              r"Host EC2 \(instance .+?\) (stopped|terminated)\.",
              task.get("stoppedReason", ""),
          ):
              raise AirflowException(
                  f"The task was stopped because the host instance terminated:"
                  f" {task.get('stoppedReason', '')}"
              )
          containers = task["containers"]
          for container in containers:
              if (
                  container.get("lastStatus") == "STOPPED"
                  and container.get("exitCode", 1) != 0
              ):
                  if self.task_log_fetcher:
                      last_logs = "\n".join(
                          self.task_log_fetcher.get_last_log_messages(
                              self.number_logs_exception
                          )
                      )
                      raise AirflowException(
                          f"This task is not in success state - last {self.number_logs_exception} "
                          f"logs from Cloudwatch:\n{last_logs}"
                      )
                  else:
                      raise AirflowException(
                          f"This task is not in success state {task}"
                      )
              elif container.get("lastStatus") == "PENDING":
                  raise AirflowException(
                      f"This task is still pending {task}"
                  )
              elif "error" in container.get("reason", "").lower():
                  raise AirflowException(
                      f"This containers encounter an error during launching: "
                      f"{container.get('reason', '').lower()}"
                  )
  
imports: from __future__ import annotations
  import re
  import warnings
  from datetime import timedelta
  from functools import cached_property
  from typing import TYPE_CHECKING, Sequence
  from airflow.configuration import conf
  from airflow.exceptions import AirflowException, AirflowProviderDeprecationWarning
  from airflow.providers.amazon.aws.exceptions import EcsOperatorError, EcsTaskFailToStart
  from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
  from airflow.providers.amazon.aws.hooks.ecs import EcsClusterStates, EcsHook, should_retry_eni
  from airflow.providers.amazon.aws.hooks.logs import AwsLogsHook
  from airflow.providers.amazon.aws.operators.base_aws import AwsBaseOperator
  from airflow.providers.amazon.aws.triggers.ecs import ClusterActiveTrigger, ClusterInactiveTrigger, TaskDoneTrigger
  from airflow.providers.amazon.aws.utils.identifiers import generate_uuid
  from airflow.providers.amazon.aws.utils.mixins import aws_template_fields
  from airflow.providers.amazon.aws.utils.task_log_fetcher import AwsTaskLogFetcher
  from airflow.utils.helpers import prune_dict
label_desc: Use image node_id 12 for calling the EcsRunTaskOperator obj's underlying member method code with example usage: obj._check_success_task() without return types