【问题标题】:Execute the task on Airflow on 12th day of the month and 2 days before the last day of the month在每月的第 12 天和每月最后一天的前 2 天执行 Airflow 上的任务
【发布时间】:2019-10-12 02:39:24
【问题描述】:

我需要在每月的第 12 天和每月最后一天的前 2 天执行气流相同的任务。

我也在尝试使用宏和execution_date。不知道如何进一步进行。你能帮忙吗?

def check_trigger(execution_date, day_offset, **kwargs):
    target_date = execution_date - timedelta(days = day_offset)
    return target_date

【问题讨论】:

  • 对于不能通过crontab表达式实现的调度条件,你可以随时依赖programming-logicskiptask(s)当你不想要的时候运行它们。

标签: airflow


【解决方案1】:

我会像下面这样处理它。 twelfth_or_two_before 是一个 Python 函数,它只检查日期并返回相应下游任务的 task_id。 (这样,如果业务需求发生变化并且您需要在不同/额外的一天运行实际任务,您只需修改该功能。)

with DAG( ... ) as dag:
    right_days = BranchPythonOperator(
        task_id="start",
        python_callable="twelfth_or_two_before,
    )
    do_nothing = DummyOperator(task_id="do_nothing")
    actual_task = ____Operator( ... )  # This is the Operator that does actual work
    start >> [do_nothing, actual_task]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-11
    • 2019-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多