Возможно ли, чтобы DAG обнаружил первый запуск в определенную дату в Airflow?

0
задан kaxil 16 January 2019 в 13:21
поделиться

1 ответ

Вы можете проверить предыдущую дату выполнения (макрос prev_ds) и сравнить ее с текущей датой выполнения (макрос ds) в BranchPythonOperator. Пример:

start = DummyOperator(task_id='start_task', dag=dag)
end = DummyOperator(task_id='end_task ', dag=dag)
once = DummyOperator(task_id='once_task', dag=dag)
dummy_task_id_that_does_nothing = DummyOperator(task_id='dummy_task_id_that_does_nothing', dag=dag)

def check_if_task_already_ran(**context):
    ds = context.get('ds')
    prev_ds = context.get('prev_ds')

    pprint(context)
    print(ds)
    print(prev_ds)

    if prev_ds == ds:
        return dummy_task_id_that_does_nothing
    else:
        return once_task    # Task that would just be executed once in a day


compare_ds = BranchPythonOperator(
    task_id='compare_ds',
    provide_context=True,
    python_callable=check_if_task_already_ran,
    dag=dag)


start >> compare_ds
compare_ds >> once >> end
compare_ds >> dummy_task_id_that_does_nothing >> end
0
ответ дан kaxil 16 January 2019 в 13:21
поделиться
Другие вопросы по тегам:

Похожие вопросы: