vincbeck commented on code in PR #28900: URL: https://github.com/apache/airflow/pull/28900#discussion_r1094867921
########## airflow/models/dag.py: ########## @@ -1298,6 +1298,48 @@ def normalized_schedule_interval(self) -> ScheduleInterval: _schedule_interval = self.schedule_interval return _schedule_interval + @staticmethod + @provide_session + def _fetch_callback(dag: DAG, dagrun: DagRun, 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 + ti.task = dag.get_task(ti.task_id) + context = ti.get_template_context(session=session) + context.update({"reason": reason}) + return callbacks, context + + @staticmethod + @internal_api_call + @provide_session + def fetch_callback(dag_id: str, run_id: str, success=True, reason=None, session=NEW_SESSION): + """ + Get DAG and DagRun objects before calling _fetch_callback method + + :param dag_id: The dag_id of the DAG to find. + :param run_id: The run_id of the DagRun to find. + :param success: Flag to specify if failure or success callback should be called + :param reason: Completion reason + :param session: Database session + """ + dag = DagModel.get_dagmodel(dag_id=dag_id, session=session) + dagrun = DAG._fetch_dagrun(dag_id=dag_id, run_id=run_id, session=session) + # TODO: need serialization here Review Comment: Left over I guess :| -- 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-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org