You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "vincbeck (via GitHub)" <gi...@apache.org> on 2023/07/12 12:36:31 UTC

[GitHub] [airflow] vincbeck commented on a diff in pull request #28900: Convert DagFileProcessor.execute_callbacks to Internal API

vincbeck commented on code in PR #28900:
URL: https://github.com/apache/airflow/pull/28900#discussion_r1261113735


##########
airflow/models/dag.py:
##########
@@ -1378,6 +1379,33 @@ def normalized_schedule_interval(self) -> ScheduleInterval:
             _schedule_interval = self.schedule_interval
         return _schedule_interval
 
+    @staticmethod
+    @internal_api_call
+    @provide_session
+    def fetch_callback(
+        dag: DAG, dagrun: DagRun | DagRunPydantic, success=True, reason=None, session=NEW_SESSION
+    ):
+        """
+        Fetch the appropriate callbacks depending on the value of success, namely the
+        on_failure_callback or on_success_callback. This method gets the context of a
+        single TaskInstance part of this DagRun and returns it along the list of callbacks.
+
+        :param dag: DAG object
+        :param dagrun: DagRun object
+        :param success: Flag to specify if failure or success callback should be called
+        :param reason: Completion reason
+        :param session: Database session
+        """
+        callbacks = dag.on_success_callback if success else dag.on_failure_callback
+        if callbacks:
+            callbacks = callbacks if isinstance(callbacks, list) else [callbacks]
+            tis = dagrun.get_task_instances(session=session)
+            ti = tis[-1]  # get first TaskInstance of DagRun

Review Comment:
   This is the current code. See [here](https://github.com/apache/airflow/blob/main/airflow/models/dag.py#L1401). Happy to optimize this one on a separate PR but I think this PR is complex enough to not address it here :)



-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org