找出触发任务以编程方式运行的原因

时间:2018-11-08 10:25:17

标签: airflow

是否有一种方法可以从操作员内部以编程方式确定是什么触发了PythonOperator的当前任务运行?

我想区分按计划触发的任务运行,追赶的任务运行和由回填CLI命令触发的任务运行。

1 个答案:

答案 0 :(得分:1)

模板上下文包含两个变量:dag_runrun_id,可用于确定运行是计划的,回填的还是外部触发的。

from airflow import jobs

def python_target(**context):
  is_backfill = context["dag_run"].is_backfill
  is_external = context["dag_run"].external_trigger
  is_latest = context["execution_date"] == context["dag"].latest_execution_date
  # More code...
相关问题