pankajkoti commented on code in PR #39442:
URL: https://github.com/apache/airflow/pull/39442#discussion_r1592192366


##########
airflow/providers/google/cloud/triggers/bigquery.py:
##########
@@ -118,7 +132,8 @@ async def run(self) -> AsyncIterator[TriggerEvent]:  # 
type: ignore[override]
                     await asyncio.sleep(self.poll_interval)
         except asyncio.CancelledError:
             self.log.info("Task was killed.")

Review Comment:
   This log may not be correct if the triggerer restarts, no?



##########
airflow/providers/google/cloud/triggers/bigquery.py:
##########
@@ -89,6 +90,19 @@ def serialize(self) -> tuple[str, dict[str, Any]]:
             },
         )
 
+    def safe_to_cancel(self) -> bool:
+        """
+        Whether it is safe to cancel the external job which is being executed 
by this trigger.
+
+        This is to avoid the case that `asyncio.CancelledError` is called 
because the trigger itself is stopped.
+        Because in those cases, we should NOT cancel the external job.
+        """
+        self.log.info("Checking if it is safe to cancel the job.")

Review Comment:
   +1



##########
airflow/providers/google/cloud/triggers/bigquery.py:
##########
@@ -118,7 +132,8 @@ async def run(self) -> AsyncIterator[TriggerEvent]:  # 
type: ignore[override]
                     await asyncio.sleep(self.poll_interval)
         except asyncio.CancelledError:
             self.log.info("Task was killed.")
-            if self.job_id and self.cancel_on_kill:
+            if self.job_id and self.cancel_on_kill and self.safe_to_cancel():
+                self.log.info("Cancelling job: %s:%s.%s", self.project_id, 
self.location, self.job_id)

Review Comment:
   ```suggestion
                   self.log.info("Cancelling job. Project ID:%s, Location: %s, 
Job ID: %s", self.project_id, self.location, self.job_id)
   ```



##########
airflow/providers/google/cloud/triggers/bigquery.py:
##########
@@ -89,6 +90,19 @@ def serialize(self) -> tuple[str, dict[str, Any]]:
             },
         )
 
+    def safe_to_cancel(self) -> bool:
+        """
+        Whether it is safe to cancel the external job which is being executed 
by this trigger.
+
+        This is to avoid the case that `asyncio.CancelledError` is called 
because the trigger itself is stopped.
+        Because in those cases, we should NOT cancel the external job.
+        """
+        self.log.info("Checking if it is safe to cancel the job.")
+        return self.task_instance not in {
+            TaskInstanceState.RUNNING,
+            TaskInstanceState.DEFERRED,
+        }

Review Comment:
   What is the value for taskinstance when task is marked failed externally?



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