vincbeck commented on code in PR #28900:
URL: https://github.com/apache/airflow/pull/28900#discussion_r1095066168
##########
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
Review Comment:
Let me take a look at it. Maybe we can kill 2 birds with one stone.
Other topic. What do you think of my serialization questions? This has been
brought up in #29188 as well. Should/can we trust `BaseSerialization.serialize`
to serialize everything or we'll have to implement custom serialization
strategy for some structures?
--
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]