pankajkoti commented on code in PR #40084:
URL: https://github.com/apache/airflow/pull/40084#discussion_r1683160153
##########
airflow/triggers/base.py:
##########
@@ -137,3 +150,105 @@ 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.
+ """
+ # Get the next kwargs of the task instance, or an empty dictionary if
it doesn't exist
+ next_kwargs = task_instance.next_kwargs or {}
+
+ # Add the event's payload into the kwargs for the task
+ next_kwargs["event"] = self.payload
+
+ # Update the next kwargs of the task instance
+ task_instance.next_kwargs = next_kwargs
+
+ # Remove ourselves as its trigger
+ task_instance.trigger_id = None
+
+ # Set the state of the task instance to scheduled
+ task_instance.state = TaskInstanceState.SCHEDULED
Review Comment:
do we need these one-liner comments?
##########
airflow/dag_processing/processor.py:
##########
@@ -763,8 +763,29 @@ def _execute_dag_callbacks(self, dagbag: DagBag, request:
DagCallbackRequest, se
if callbacks and context:
DAG.execute_callback(callbacks, context, dag.dag_id)
- def _execute_task_callbacks(self, dagbag: DagBag | None, request:
TaskCallbackRequest, session: Session):
- if not request.is_failure_callback:
+ def _execute_task_callbacks(
+ self, dagbag: DagBag | None, request: TaskCallbackRequest, session:
Session
+ ) -> None:
+ """
+ Execute the task callbacks.
+
+ :param dagbag: the DagBag to use to get the task instance
+ :param request: the task callback request
+ :param session: the session to use
+ """
+ try:
+ callback_type = TaskInstanceState(request.task_callback_type)
+ except ValueError:
+ callback_type = None
+ is_remote = callback_type in (TaskInstanceState.SUCCESS,
TaskInstanceState.FAILED)
Review Comment:
+1
--
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]