aurangzaib048 commented on code in PR #64770:
URL: https://github.com/apache/airflow/pull/64770#discussion_r3122898348


##########
providers/amazon/src/airflow/providers/amazon/aws/operators/emr.py:
##########
@@ -604,10 +610,19 @@ def check_failure(self, query_status):
     def execute_complete(self, context: Context, event: dict[str, Any] | None 
= None) -> str:
         validated_event = validate_execute_complete_event(event)
 
-        if validated_event["status"] != "success":
-            raise AirflowException(f"Error while running job: 
{validated_event}")
-
-        return validated_event["job_id"]
+        if validated_event["status"] == "success":
+            return validated_event["job_id"]
+        job_id = validated_event.get("job_id")
+        if job_id:
+            self.log.info("Cancelling EMR container job %s", job_id)
+            try:
+                self.hook.stop_query(job_id)

Review Comment:
   Fixed in c0fc64c. Added `and self.cancel_on_kill` guard so cancellation in 
`execute_complete()` is skipped when `cancel_on_kill=False`, matching the 
trigger-side behavior.



##########
providers/amazon/src/airflow/providers/amazon/aws/operators/emr.py:
##########
@@ -604,10 +610,19 @@ def check_failure(self, query_status):
     def execute_complete(self, context: Context, event: dict[str, Any] | None 
= None) -> str:
         validated_event = validate_execute_complete_event(event)
 
-        if validated_event["status"] != "success":
-            raise AirflowException(f"Error while running job: 
{validated_event}")
-
-        return validated_event["job_id"]
+        if validated_event["status"] == "success":
+            return validated_event["job_id"]
+        job_id = validated_event.get("job_id")
+        if job_id:

Review Comment:
   Good point. Fixed in 88172f4 — `execute_complete` now only cancels on 
explicit `status == "error"` instead of an else branch, so any future trigger 
status won't silently fall into the cancel path.



##########
providers/amazon/src/airflow/providers/amazon/aws/operators/emr.py:
##########
@@ -604,10 +610,19 @@ def check_failure(self, query_status):
     def execute_complete(self, context: Context, event: dict[str, Any] | None 
= None) -> str:
         validated_event = validate_execute_complete_event(event)
 
-        if validated_event["status"] != "success":
-            raise AirflowException(f"Error while running job: 
{validated_event}")
-
-        return validated_event["job_id"]
+        if validated_event["status"] == "success":
+            return validated_event["job_id"]
+        job_id = validated_event.get("job_id")
+        if job_id:
+            self.log.info("Cancelling EMR container job %s", job_id)
+            try:
+                self.hook.stop_query(job_id)

Review Comment:
   Addressed in c0fc64c — `execute_complete` now respects `cancel_on_kill` 
before invoking `stop_query`.



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