pingzh commented on code in PR #22917:
URL: https://github.com/apache/airflow/pull/22917#discussion_r848675598
##########
airflow/models/serialized_dag.py:
##########
@@ -220,6 +220,36 @@ def remove_dag(cls, dag_id: str, session: Session = None):
"""
session.execute(cls.__table__.delete().where(cls.dag_id == dag_id))
+ @classmethod
+ @provide_session
+ def remove_unknown_dags_in_dag_file(
+ cls, active_dag_ids: List[str], dag_file_path: str, session=None
+ ) -> List[str]:
+ """
+ Deletes serialized_dags whose dag_ids are not in the active_dag_ids
for a given dag_file_path
+
+ :return: a list of inactive dag ids
+ :rtype: list[str]
+ """
+ file_path_hash = DagCode.dag_fileloc_hash(dag_file_path)
+ # there is a db index on fileloc_hash
+ rows = session.query(cls.dag_id).filter(cls.fileloc_hash ==
file_path_hash).all()
+ dag_ids_from_db = [i[0] for i in rows]
+
+ dag_ids_to_remove = [dag_id for dag_id in dag_ids_from_db if dag_id
not in active_dag_ids]
Review Comment:
after reading the implementation of `dag_fileloc_hash`, it makes sense to do
the check. updated.
--
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]