ashb commented on a change in pull request #14263:
URL: https://github.com/apache/airflow/pull/14263#discussion_r583740272
##########
File path: airflow/providers/amazon/aws/operators/ecs.py
##########
@@ -27,6 +27,7 @@
from airflow.models import BaseOperator
from airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
from airflow.providers.amazon.aws.hooks.logs import AwsLogsHook
+from airflow.providers.amazon.aws.models.exceptions import ECSOperatorError
Review comment:
```suggestion
from airflow.providers.amazon.aws.exceptions import ECSOperatorError
```
I think would be better name.
##########
File path: airflow/providers/amazon/aws/hooks/base_aws.py
##########
@@ -40,8 +41,32 @@
from airflow.exceptions import AirflowException
from airflow.hooks.base import BaseHook
from airflow.models.connection import Connection
+from airflow.providers.amazon.aws.models.exceptions import ECSOperatorError
from airflow.utils.log.logging_mixin import LoggingMixin
+ECS_QUOTA_ERROR_REASONS = [
Review comment:
Since these are ECS specific they shouldn't really be in the base_aws
module.
##########
File path: airflow/providers/amazon/aws/models/exceptions.py
##########
@@ -0,0 +1,29 @@
+#
+# 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.
+#
+# Note: Any AirflowException raised is expected to cause the TaskInstance
+# to be marked in an ERROR state
+
+
+class ECSOperatorError(Exception):
+ """Raise when ECS cannot handle the request."""
+
+ def __init__(self, failures: list, message: str):
+ self.failures = failures
+ self.message = message
+ super().__init__(self.message)
Review comment:
```suggestion
super().__init__(message)
```
##########
File path: airflow/providers/amazon/aws/hooks/base_aws.py
##########
@@ -484,6 +509,34 @@ def expand_role(self, role: str) -> str:
else:
return
self.get_client_type("iam").get_role(RoleName=role)["Role"]["Arn"]
+ @staticmethod
+ def retry(fun: Callable):
+ """
+ A decorator that provides a mechanism to repeat requests in response
to exceeding a temporary quote
+ limit.
+ """
+
+ def decorator_f(self):
+ quota_retry = getattr(self, 'quota_retry', None)
+ if quota_retry is None:
+ return fun(self)
+ multiplier = quota_retry.get('multiplier', 1)
+ min_limit = quota_retry.get('min', 1)
+ max_limit = quota_retry.get('max', 1)
+ stop_after_delay = quota_retry.get('stop_after_delay', 10)
+ logger = quota_retry.get('logger')
Review comment:
Why not self.logger?
##########
File path: airflow/providers/amazon/aws/operators/ecs.py
##########
@@ -150,6 +151,7 @@ def __init__(
awslogs_region: Optional[str] = None,
awslogs_stream_prefix: Optional[str] = None,
propagate_tags: Optional[str] = None,
+ quota_retry: Optional[dict] = None,
Review comment:
Please add docs for this parameter.
##########
File path: airflow/providers/amazon/aws/hooks/base_aws.py
##########
@@ -484,6 +509,34 @@ def expand_role(self, role: str) -> str:
else:
return
self.get_client_type("iam").get_role(RoleName=role)["Role"]["Arn"]
+ @staticmethod
+ def retry(fun: Callable):
+ """
+ A decorator that provides a mechanism to repeat requests in response
to exceeding a temporary quote
+ limit.
+ """
+
+ def decorator_f(self):
+ quota_retry = getattr(self, 'quota_retry', None)
Review comment:
Not sure about this parameter name -- it seems very specific to
EcsOperator only.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
[email protected]