停止气流回填运行

时间:2021-06-12 08:01:28

标签: python airflow airflow-scheduler

我使用的是 Airflow 1.9.0 版本。

DAG 每分钟都在运行。但是当 Airflow 关闭一段时间左右时,我们会看到大量回填作业正在运行,这会停止最近的 DAG 运行。

我正在使用 SubDagOperator。

dag_args = {
    'owner': 'Anish',
    'depends_on_past': False,
    'start_date': datetime.datetime(2017, 3, 20),#time in past
    'retries': 0,
    'retry_delay': datetime.timedelta(seconds=5),
    'email':Variable.get("failure_email_to"),
    'email_on_failure': False
}

dag = DAG(DAG_NAME, catchup=False, default_args=dag_args, schedule_interval="*/1 * * * *")

describe_table_by_fip_codes = SubDagOperator(
    task_id='process_flatten_sequences',
    subdag=subdag(DAG_NAME, 'process_flatten_sequences', dag_args),
    default_args=dag_args,
    dag=dag,
)


def subdag(parent_dag_name, child_dag_name, args):
    workerNumbers = 10
    next_subtask_interval = 10
    dag_subdag = DAG(
        dag_id='%s.%s' % (parent_dag_name, child_dag_name),
        default_args=args,
        schedule_interval='@once',
        catchup=False
    )

    for workerNumber in range(workerNumbers):
        sleep_time =  next_subtask_interval * workerNumber
        
        process_data = PythonOperator(
            task_id='{}_flatten_new_sequences_worker_{}'.format(child_dag_name, workerNumber),
            provide_context=True,
            python_callable=processSequences,
            default_args=args,
            op_kwargs={'sleep_time': sleep_time},
            dag=dag_subdag)

    return dag_subdag


def processSequences(sleep_time=0, **context):
    logger.info(f"sleeping for {sleep_time} seconds")
    sleep(sleep_time)
    #Start actual code execution logic after sleep


Airflow Configurations 
parallelism=64
dag_concurrency=64
celeryd_concurrency=64
max_active_runs_per_dag=32
non_pooled_task_slot_count=128


如您所见,我也在airflow.cfg 中使用了catchup=False 和catchup_by_default=False,但回填任务仍在进行中。

我不确定它是否与 Airflow 1.9.0 版本有关。 我浏览了来自 stackoverflow 的文章和其他帖子,但每个人都提出了我已经在使用的相同内容(catchup=False)。

任何帮助将不胜感激。

提前致谢

enter image description here

1 个答案:

答案 0 :(得分:0)

如果 catchup 设置为 False,Airflow 将不会在关闭的时间段内回填。可能是您使用的版本存在错误。

另一种选择是使用 latest_only 运算符,如果 DAG 运行不是最新的,它将跳过其余任务。在这种情况下,DAG 运行仍将被创建,但下游任务将被跳过。