SameerMesiah97 commented on code in PR #71653:
URL: https://github.com/apache/airflow/pull/71653#discussion_r3833457613


##########
providers/amazon/src/airflow/providers/amazon/aws/triggers/sagemaker.py:
##########
@@ -108,6 +108,90 @@ def hook(self) -> AwsGenericHook:
             config=self.botocore_config,
         )
 
+    async def run(self) -> AsyncIterator[TriggerEvent]:
+        hook = self.hook()
+
+        async with await hook.get_async_conn() as conn:
+            waiter = hook.get_waiter(
+                self.waiter_name,
+                deferrable=True,
+                client=conn,
+            )
+
+            for _ in range(self.attempts):
+                try:
+                    await waiter.wait(
+                        **self.waiter_args,
+                        WaiterConfig={"MaxAttempts": 1},
+                    )
+                except WaiterError as error:
+                    response = error.last_response
+                    status = 
response.get(self._get_response_status_key(self.job_type))
+
+                    if status == "Failed":
+                        yield TriggerEvent(
+                            {
+                                "status": "failed",
+                                "job_name": self.job_name,
+                                "message": response.get("FailureReason"),
+                            }
+                        )
+                        return
+
+                    if status == "Stopped":
+                        yield TriggerEvent(
+                            {
+                                "status": "stopped",
+                                "job_name": self.job_name,
+                            }
+                        )
+                        return
+
+                    self._log_job_status(response)
+                    await asyncio.sleep(self.waiter_delay)

Review Comment:
   The first iteration is now skipped and the sleep has been moved to the 
beginning of the loop.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to