Skip to content

Commit 525d7f3

Browse files
DEVO-662-scheduler-log-cleanup (#1688)
* add cleanup commands for scheduler log files * change 7 to 30 days
1 parent 046f6ce commit 525d7f3

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Module providing a function to remove old schedluer logs."""
2+
from datetime import datetime, timedelta
3+
from airflow import DAG
4+
from airflow.operators.bash import BashOperator
5+
6+
default_args = {
7+
'owner': 'airflow',
8+
'depends_on_past': False,
9+
'start_date': datetime(2023, 1, 1), # Adjust the start date as needed
10+
'retries': 1,
11+
'retry_delay': timedelta(minutes=5)
12+
}
13+
14+
with DAG(
15+
'cleanup_scheduler_logs',
16+
default_args=default_args,
17+
description='Remove folders older than 30 days from /var/lib/airflow/airflow-app/logs/scheduler',
18+
schedule_interval='@daily', # Runs once a day
19+
catchup=False,
20+
) as dag:
21+
22+
cleanup_old_folders = BashOperator(
23+
task_id='cleanup_old_folders',
24+
bash_command=(
25+
"find /var/lib/airflow/airflow-app/logs/scheduler "
26+
"-mindepth 1 -maxdepth 1 -type d -mtime +30 -exec rm -rf {} +"
27+
)
28+
)

0 commit comments

Comments
 (0)