This is an automated email from the ASF dual-hosted git repository.

potiuk pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new b1c2b07e58 Refactor: Simplify loop in aws/triggers/batch.py (#34052)
b1c2b07e58 is described below

commit b1c2b07e581d7040859bc44abea8bacde2705627
Author: Miroslav Šedivý <[email protected]>
AuthorDate: Mon Sep 4 09:49:42 2023 +0000

    Refactor: Simplify loop in aws/triggers/batch.py (#34052)
---
 airflow/providers/amazon/aws/triggers/batch.py | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/airflow/providers/amazon/aws/triggers/batch.py 
b/airflow/providers/amazon/aws/triggers/batch.py
index 2bf9e95062..c1b3770dd5 100644
--- a/airflow/providers/amazon/aws/triggers/batch.py
+++ b/airflow/providers/amazon/aws/triggers/batch.py
@@ -80,9 +80,7 @@ class BatchOperatorTrigger(BaseTrigger):
 
         async with self.hook.async_conn as client:
             waiter = self.hook.get_waiter("batch_job_complete", 
deferrable=True, client=client)
-            attempt = 0
-            while attempt < self.max_retries:
-                attempt = attempt + 1
+            for attempt in range(1, 1 + self.max_retries):
                 try:
                     await waiter.wait(
                         jobs=[self.job_id],
@@ -91,7 +89,6 @@ class BatchOperatorTrigger(BaseTrigger):
                             "MaxAttempts": 1,
                         },
                     )
-                    break
                 except WaiterError as error:
                     if "terminal failure" in str(error):
                         yield TriggerEvent(
@@ -105,11 +102,11 @@ class BatchOperatorTrigger(BaseTrigger):
                         self.max_retries,
                     )
                     await asyncio.sleep(int(self.poll_interval))
-
-        if attempt >= self.max_retries:
-            yield TriggerEvent({"status": "failure", "message": "Job Failed - 
max attempts reached."})
-        else:
-            yield TriggerEvent({"status": "success", "job_id": self.job_id})
+                else:
+                    yield TriggerEvent({"status": "success", "job_id": 
self.job_id})
+                    break
+            else:
+                yield TriggerEvent({"status": "failure", "message": "Job 
Failed - max attempts reached."})
 
 
 @deprecated(reason="use BatchJobTrigger instead")

Reply via email to