Skip to content

Commit ef6bca5

Browse files
authored
Update Cleanup DAG (#10771)
* Update Cleanup DAG * Update airflow_db_cleanup.py Missing empty line at the end.
1 parent f1d70e2 commit ef6bca5

1 file changed

Lines changed: 29 additions & 8 deletions

File tree

composer/workflows/airflow_db_cleanup.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353

5454
import airflow
5555
from airflow import settings
56-
from airflow.jobs.base_job import BaseJob
5756
from airflow.models import (
5857
DAG,
5958
DagModel,
@@ -101,13 +100,6 @@
101100
# List of all the objects that will be deleted. Comment out the DB objects you
102101
# want to skip.
103102
DATABASE_OBJECTS = [
104-
{
105-
"airflow_db_model": BaseJob,
106-
"age_check_column": BaseJob.latest_heartbeat,
107-
"keep_last": False,
108-
"keep_last_filters": None,
109-
"keep_last_group_by": None,
110-
},
111103
{
112104
"airflow_db_model": DagRun,
113105
"age_check_column": DagRun.execution_date,
@@ -228,6 +220,35 @@
228220
except Exception as e:
229221
logging.error(e)
230222

223+
if AIRFLOW_VERSION < ["2", "6", "0"]:
224+
try:
225+
from airflow.jobs.base_job import BaseJob
226+
DATABASE_OBJECTS.append(
227+
{
228+
"airflow_db_model": BaseJob,
229+
"age_check_column": BaseJob.latest_heartbeat,
230+
"keep_last": False,
231+
"keep_last_filters": None,
232+
"keep_last_group_by": None,
233+
}
234+
)
235+
except Exception as e:
236+
logging.error(e)
237+
else:
238+
try:
239+
from airflow.jobs.job import Job
240+
DATABASE_OBJECTS.append(
241+
{
242+
"airflow_db_model": Job,
243+
"age_check_column": Job.latest_heartbeat,
244+
"keep_last": False,
245+
"keep_last_filters": None,
246+
"keep_last_group_by": None,
247+
}
248+
)
249+
except Exception as e:
250+
logging.error(e)
251+
231252
default_args = {
232253
"owner": DAG_OWNER_NAME,
233254
"depends_on_past": False,

0 commit comments

Comments
 (0)