ksharlandjiev commented on code in PR #57753:
URL: https://github.com/apache/airflow/pull/57753#discussion_r2599037219
##########
providers/amazon/src/airflow/providers/amazon/aws/operators/ssm.py:
##########
@@ -132,14 +143,36 @@ def execute(self, context: Context):
instance_ids = response["Command"]["InstanceIds"]
for instance_id in instance_ids:
- waiter.wait(
- CommandId=command_id,
- InstanceId=instance_id,
- WaiterConfig={
- "Delay": self.waiter_delay,
- "MaxAttempts": self.waiter_max_attempts,
- },
- )
+ try:
+ waiter.wait(
+ CommandId=command_id,
+ InstanceId=instance_id,
+ WaiterConfig={
+ "Delay": self.waiter_delay,
+ "MaxAttempts": self.waiter_max_attempts,
+ },
+ )
+ except WaiterError:
+ if not self.fail_on_nonzero_exit:
+ # Enhanced mode: distinguish between AWS-level and
command-level failures
+ invocation =
self.hook.get_command_invocation(command_id, instance_id)
+ status = invocation.get("Status", "")
+
+ # AWS-level failures should always raise
+ if status in ("Cancelled", "TimedOut"):
Review Comment:
Yes. I have double checked the documentation. However, to make things
easier, I've added `SsmHook.is_aws_level_failure()` helper method with the
statuses list.
##########
providers/amazon/src/airflow/providers/amazon/aws/operators/ssm.py:
##########
@@ -132,14 +143,36 @@ def execute(self, context: Context):
instance_ids = response["Command"]["InstanceIds"]
for instance_id in instance_ids:
- waiter.wait(
- CommandId=command_id,
- InstanceId=instance_id,
- WaiterConfig={
- "Delay": self.waiter_delay,
- "MaxAttempts": self.waiter_max_attempts,
- },
- )
+ try:
+ waiter.wait(
+ CommandId=command_id,
+ InstanceId=instance_id,
+ WaiterConfig={
+ "Delay": self.waiter_delay,
+ "MaxAttempts": self.waiter_max_attempts,
+ },
+ )
+ except WaiterError:
+ if not self.fail_on_nonzero_exit:
+ # Enhanced mode: distinguish between AWS-level and
command-level failures
+ invocation =
self.hook.get_command_invocation(command_id, instance_id)
+ status = invocation.get("Status", "")
+
+ # AWS-level failures should always raise
+ if status in ("Cancelled", "TimedOut"):
+ self.log.error("Command failed with AWS-level
error: %s", status)
Review Comment:
removed.
--
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]