sunank200 commented on code in PR #40084:
URL: https://github.com/apache/airflow/pull/40084#discussion_r1684695310


##########
airflow/triggers/base.py:
##########
@@ -137,3 +150,96 @@ def __eq__(self, other):
         if isinstance(other, TriggerEvent):
             return other.payload == self.payload
         return False
+
+    @provide_session
+    def handle_submit(self, *, task_instance: TaskInstance, session: Session = 
NEW_SESSION) -> None:
+        """
+        Handle the submit event for a given task instance.
+
+        This function sets the next method and next kwargs of the task 
instance,
+        as well as its state to scheduled. It also adds the event's payload
+        into the kwargs for the task.
+
+        :param task_instance: The task instance to handle the submit event for.
+        :param session: The session to be used for the database callback sink.
+        """
+        next_kwargs = task_instance.next_kwargs or {}
+        next_kwargs["event"] = self.payload
+        task_instance.next_kwargs = next_kwargs
+        task_instance.trigger_id = None
+        task_instance.state = TaskInstanceState.SCHEDULED
+
+
+class BaseTaskEndEvent(TriggerEvent):
+    """Base event class to end the task without resuming on worker."""
+
+    task_instance_state: TaskInstanceState
+
+    def __init__(self, *, xcoms: dict[str, Any] | None = None, **kwargs) -> 
None:
+        """
+        Initialize the class with the specified parameters.
+
+        :param xcoms: A dictionary of XComs or None.
+        :param kwargs: Additional keyword arguments.
+        """
+        if "payload" in kwargs:
+            raise ValueError("Param 'payload' not supported for this class.")
+        super().__init__(payload=self.task_instance_state)
+        self.xcoms = xcoms
+
+    @provide_session
+    def handle_submit(self, *, task_instance: TaskInstance, session: Session = 
NEW_SESSION) -> None:
+        """
+        Submit event for the given task instance.
+
+        Marks the task with the state `task_instance_state` and optionally 
pushes xcom if applicable.
+
+        :param task_instance: The task instance to be submitted.
+        :param session: The session to be used for the database callback sink.
+        """
+        # Mark the task with terminal state and prevent it from resuming on 
worker
+        task_instance.trigger_id = None
+        task_instance.state = self.task_instance_state
+
+        self._submit_callback_if_necessary(task_instance=task_instance, 
session=session)
+        self._push_xcoms_if_necessary(task_instance=task_instance)
+
+    def _submit_callback_if_necessary(self, *, task_instance: TaskInstance, 
session) -> None:
+        """Submit a callback request if the task state is SUCCESS or FAILED."""
+        is_failure = self.task_instance_state == TaskInstanceState.FAILED
+        if self.task_instance_state in [TaskInstanceState.SUCCESS, 
TaskInstanceState.FAILED]:

Review Comment:
   Changed it



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