Apache 气流:将 catchup 设置为 False 不起作用

Apache airflow: setting catchup to False is not working

我在 Apache airflow 上创建了一个 DAG。从 2015 年 6 月开始,调度程序似乎配置为 运行(顺便说一句。我不知道为什么,但这是我创建的新 DAG,我没有回填它,我只用不同的回填其他 dags具有这些日期间隔的 DAG ID,调度程序获取了这些日期并回填了我的新 dag。我开始使用气流)。

(更新:我意识到 DAG 被回填了,因为开始日期是在 DAG 默认配置上设置的,尽管这不能解释我在下面公开的行为)

我正在尝试停止调度程序以运行 从该日期开始执行所有 DAG。 airflow backfill --mark_success tutorial2 -s '2015-06-01' -e '2019-02-27' 命令给我数据库错误(见下文),所以我试图将 catchup 设置为 False。

sqlalchemy.exc.OperationalError: (sqlite3.OperationalError) no such table: job [SQL: 'INSERT INTO job (dag_id, state, job_type, start_date, end_date, latest_heartbeat, executor_class, hostname, unixname) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)'] [parameters: ('tutorial2', 'running', 'BackfillJob', '2019-02-27 10:52:37.281716', None, '2019-02-27 10:52:37.281733', 'SequentialExecutor', '08b6eb432df9', 'airflow')] (Background on this error at: http://sqlalche.me/e/e3q8)

所以我正在使用另一种方法。我尝试过的:

  1. 在 airflow.cfg 中设置 catchup_by_default = False 并重新启动 整个 docker 个容器。
  2. 在我的 python DAG 文件上设置 catchup = False 并启动该文件 再次 python。

我在网上看到的内容 UI:

DAG 的执行将从 2015 年 6 月开始: [![DAG 的执行将从 2015 年 6 月开始。][1]][1] [1]: https://i.stack.imgur.com/7hlL9.png

在 DAG 的配置中,Catchup 设置为 False:

[![在 DAG 的配置中 Catchup 设置为 False][2]][2] [2]: https://i.stack.imgur.com/E01Cc.png

所以我不明白为什么要启动那些 DAG 的执行。

谢谢

DAG代码:

"""
Code that goes along with the Airflow tutorial is located at:
https://github.com/apache/airflow/blob/master/airflow/example_dags/tutorial.py
"""
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta


default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': datetime(2015, 6, 1),
    'email': ['airflow@example.com'],
    'email_on_failure': False,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': timedelta(minutes=5),
    'catchup' : False,
    # 'queue': 'bash_queue',
    # 'pool': 'backfill',
    # 'priority_weight': 10,
    # 'end_date': datetime(2016, 1, 1),
}

dag = DAG(
    'tutorial2', default_args=default_args, schedule_interval='* * * * *')

# t1, t2 and t3 are examples of tasks created by instantiating operators
t1 = BashOperator(
    task_id='print_date',
    bash_command='date',
    dag=dag)

t2 = BashOperator(
    task_id='sleep',
    bash_command='sleep 5',
    retries=3,
    dag=dag)

templated_command = """
    {% for i in range(5) %}
        echo "{{ ds }}"
        echo "{{ macros.ds_add(ds, 7)}}"
        echo "{{ params.my_param }}"
    {% endfor %}
"""

t3 = BashOperator(
    task_id='templated',
    bash_command=templated_command,
    params={'my_param': 'Parameter I passed in'},
    dag=dag)

t2.set_upstream(t1)
t3.set_upstream(t1)

我认为您实际上需要在 dag 级别指定追赶,而不是通过 default_args 传递。 (无论如何,后者实际上没有任何意义,因为这些是任务的默认参数。您不能让一些任务赶上而另一些则不能。)

试试这个:

dag = DAG(
    'tutorial2', default_args=default_args, schedule_interval='* * * * *', catchup=False)