TakawaAkirayo commented on code in PR #41232:
URL: https://github.com/apache/airflow/pull/41232#discussion_r1716512066


##########
airflow/jobs/triggerer_job_runner.py:
##########
@@ -751,3 +757,28 @@ def get_trigger_by_classpath(self, classpath: str) -> 
type[BaseTrigger]:
         if classpath not in self.trigger_cache:
             self.trigger_cache[classpath] = import_string(classpath)
         return self.trigger_cache[classpath]
+
+    @staticmethod
+    def add_trigger_cancel_reasons(
+        triggerer_id, cancel_trigger_ids: set[int]
+    ) -> list[tuple[int, TriggerTerminationReason]]:
+        """
+        Add trigger cancel reasons to give consumer more context.
+
+        Currently, we only distinguish between reassigned and other reasons.
+        """
+
+        def add_reason(
+            ids: set[int], reason: TriggerTerminationReason
+        ) -> list[tuple[int, TriggerTerminationReason]]:
+            return [(trigger_id, reason) for trigger_id in ids]
+
+        # find out reassigned triggers
+        reassigned_trigger_ids = 
set(Trigger.filter_out_reassigned_triggers(triggerer_id, cancel_trigger_ids))
+
+        other_reasons_trigger_ids = cancel_trigger_ids - reassigned_trigger_ids
+
+        trigger_id_reasons = add_reason(reassigned_trigger_ids, 
TriggerTerminationReason.REASSIGNED)
+        trigger_id_reasons.extend(add_reason(other_reasons_trigger_ids, 
TriggerTerminationReason.OTHER))
+
+        return trigger_id_reasons

Review Comment:
   I agree. I initially thought the reasons might be expanded here, but since 
there are currently only two types, let's adopt your suggestion



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