Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 1 addition & 11 deletions providers/amazon/src/airflow/providers/amazon/aws/hooks/ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

from typing import TYPE_CHECKING, Protocol, runtime_checkable

from airflow.providers.amazon.aws.exceptions import EcsOperatorError, EcsTaskFailToStart
from airflow.providers.amazon.aws.exceptions import EcsOperatorError
from airflow.providers.amazon.aws.hooks.base_aws import AwsGenericHook
from airflow.providers.amazon.aws.utils import _StringCompareEnum

Expand All @@ -38,16 +38,6 @@ def should_retry(exception: Exception):
return False


def should_retry_eni(exception: Exception):
"""Check if exception is related to ENI (Elastic Network Interfaces)."""
if isinstance(exception, EcsTaskFailToStart):
return any(
eni_reason in exception.message
for eni_reason in ["network interface provisioning", "ResourceInitializationError"]
)
return False


class EcsClusterStates(_StringCompareEnum):
"""Contains the possible State values of an ECS Cluster."""

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
from airflow.configuration import conf
from airflow.exceptions import AirflowException
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.ecs import EcsClusterStates, EcsHook
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 (
Expand Down Expand Up @@ -688,7 +687,6 @@ def _get_task_log_fetcher(self) -> AwsTaskLogFetcher:
logger=self.log,
)

@AwsBaseHook.retry(should_retry_eni)
def _check_success_task(self) -> None:
if not self.client or not self.arn:
return
Expand All @@ -701,11 +699,6 @@ def _check_success_task(self) -> None:

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
Expand Down
23 changes: 2 additions & 21 deletions providers/amazon/tests/unit/amazon/aws/hooks/test_ecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import pytest

from airflow.providers.amazon.aws.exceptions import EcsOperatorError, EcsTaskFailToStart
from airflow.providers.amazon.aws.hooks.ecs import EcsHook, should_retry, should_retry_eni
from airflow.providers.amazon.aws.exceptions import EcsOperatorError
from airflow.providers.amazon.aws.hooks.ecs import EcsHook, should_retry

DEFAULT_CONN_ID: str = "aws_default"
REGION: str = "us-east-1"
Expand Down Expand Up @@ -59,22 +59,3 @@ def test_return_true_on_valid_reason(self):

def test_return_false_on_invalid_reason(self):
assert not should_retry(EcsOperatorError([{"reason": "CLUSTER_NOT_FOUND"}], "Foo"))


class TestShouldRetryEni:
def test_return_true_on_valid_reason(self):
assert should_retry_eni(
EcsTaskFailToStart(
"The task failed to start due to: "
"Timeout waiting for network interface provisioning to complete."
)
)

def test_return_false_on_invalid_reason(self):
assert not should_retry_eni(
EcsTaskFailToStart(
"The task failed to start due to: "
"CannotPullContainerError: "
"ref pull has been retried 5 time(s): failed to resolve reference"
)
)