【问题标题】:How can I retrieve the 'scheduled time' for catchup jobs in Airflow?如何在 Airflow 中检索追赶作业的“预定时间”?
【发布时间】:2017-11-02 12:28:58
【问题描述】:

在构建 Airflow dag 时,我通常会指定一个简单的计划来定期运行 - 我希望这是最常见的用途。

dag = DAG('my_dag',
      description='this is what it does',
      schedule_interval='0 12 * * *',
      start_date=datetime(2017, 10, 1),
      catchup=False)

然后我需要在我的实际过程中使用“日期”作为参数,所以我只检查当前日期。

date = datetime.date.today()
# do some date-sensitive stuff
operator = MyOperator(..., params=[date, ...])

我的理解是,设置 catchup=True 将使 Airflow 为 start_date 和现在(或 end_date)之间的每个计划间隔安排我的 dag;例如每天。

如何获取 scheduled_date 以在我的 dag 实例中使用?

【问题讨论】:

    标签: airflow apache-airflow


    【解决方案1】:

    我想你的意思是这里的执行日期,你可以在你的操作符中使用宏,更多细节可以在这里找到:https://airflow.apache.org/code.html#macros。所以气流会尊重它,所以你不需要动态生成你的date

    在 Operator 内部,可以直接在 str 中调用{{ ds }}

    在运算符之外,例如 PythonOperator,您首先需要provide_context=True,然后将**kwargs 作为最后一个参数传递给您的函数,然后您可以调用kwargs['ds']

    【讨论】:

    • 完美。在我看来execution date 是任务实际运行的时间,它总是“现在”,但这是有道理且有效的。
    • @Chengzhi 我们如何在 DockerOperator 中做到这一点。 stackoverflow.com/questions/51608355/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-05
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    • 1970-01-01
    • 2018-01-29
    • 2013-01-18
    相关资源
    最近更新 更多