气流计划阻止立即执行

2024-06-09 16:35:50 发布

您现在位置:Python中文网/ 问答频道 /正文

在我们的气流安装中,我们使用UTC,但确实有一些日常工作需要更改夏令时。当我们退出夏令时,这意味着我们必须将日程提前一小时。
不幸的是,这也意味着这些作业会立即执行,因为调度程序发现该作业在过去24小时内未执行,因此必须是再次运行的时间。
我知道我们可以设置DAG开始日期以防止首次运行。是否有其他方法可以完成更改计划,但要等待下一个间隔来运行作业?
我们在每月或每周创造就业机会方面也有类似的问题。DAG开始日期是处理这些问题的正确方法吗?
此外,如果是,应如何设置开始日期?
例如,如果我有一个作业设置为“0 4***”,然后我将其更改为“0 5***”,那么如果我将开始日期设置为2020年11月5日,它将在11月5日上午5点执行,还是在开始日期后等待第一个完整的执行间隔,并在11月6日上午5点运行


Tags: 方法程序间隔作业时间调度日程计划
1条回答
网友
1楼 · 发布于 2024-06-09 16:35:50

不建议根据气流的official confluence space更改气流的计划间隔,而应创建新的dag_id:

When needing to change your start_date and schedule interval, change the name of the dag (a.k.a. dag_id) - I follow the convention : my_dag_v1, my_dag_v2, my_dag_v3, my_dag_v4, etc...

Changing schedule interval always requires changing the dag_id, because previously run TaskInstances will not align with the new schedule interval.

Changing start_date without changing schedule_interval is safe, but changing to an earlier start_date will not create any new DagRuns for the time between the new start_date and the old one, so tasks will not automatically backfill to the new dates. If you manually create DagRuns, tasks will be scheduled, as long as the DagRun date is after both the task start_date and the dag start_date.

如果希望始终根据本地时间安排DAG,可以在开始日期内指定时区tzinfo。以下DAG将始终在当地时间4:30运行,无论夏季和冬季

from datetime import datetime, timedelta
from pendulum import timezone
import pendulum

default_args = {
    'depends_on_past': False,
    'wait_for_downstream': False,
    'start_date': datetime(2020, 7, 16, tzinfo=timezone('Europe/Berlin')),
    'email_on_failure': True,
    'email_on_retry': False,
    'retries': 3,
    'retry_delay': timedelta(minutes=5),
    'sla': timedelta(hours=1)
}

# Set Schedule
SCHEDULE_INTERVAL = '40 3 * * *'

# Define DAG
dag_audit_query_logs = DAG('local_tz_dag', default_args=default_args,
                           catchup=False,
                           max_active_runs=3,
                           schedule_interval=SCHEDULE_INTERVAL)

相关问题 更多 >