如何检索Airflow中的追赶作业的“预定时间”?

时间:2017-11-02 12:28:58

标签: airflow apache-airflow

在构建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'作为参数,所以我只检查当前日期。

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

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

如何在我的dag实例中使用scheduled_date

1 个答案:

答案 0 :(得分:2)

I think you mean execution date here, You can use Macros inside your operators, more detail can be found here: https://airflow.apache.org/code.html#macros. So airflow will respect it so you don't need to have your date been generated dynamically

Inside of Operator, you can call {{ ds }} in a str directly

Outside of Operator, for example PythonOperator, you will need provide_context=True first then to pass **kwargs as last arguments to your function then you can call kwargs['ds']