ramitkataria commented on code in PR #71653:
URL: https://github.com/apache/airflow/pull/71653#discussion_r3806000585
##########
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))
Review Comment:
What's in `last_response` when the `DescribeTrainingJob` call itself fails?
Bad job name, or a role without `sagemaker:DescribeTrainingJob`? Does `status`
get a value on that path, and where does the loop go next? Worth checking
against the endpoint operator, which doesn't pass `waiter_max_attempts`.
##########
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:
Review Comment:
`async_wait` also catches `NoCredentialsError` (added in #48946 for
credential refresh during long jobs). Where does it go now?
Also, `error` is bound but never used, and `message` is only
`FailureReason`. What does the operator's `AirflowException` show when
`FailureReason` is absent?
##########
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:
`async_wait` sleeps at the top of the loop, skipped on the first pass. This
sleeps at the bottom. On the final iteration, what is the sleep waiting for?
--
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]