我如何确定DAG在气流中是否已暂停/未暂停?

时间:2018-12-27 08:49:47

标签: python airflow directed-acyclic-graphs airflow-scheduler

我想暂停空闲和冗余的DAG,我如何知道哪些DAG未暂停并且哪些DAG已暂停?

因此,我有一个使用执行airflow pause <dag_id>的bash命令将要取消暂停的DAG列表。我想通过检查每个DAG的pause的状态来知道命令是否成功。我检查了airflow webserver,似乎所有暂停的DAG仍在运行。

def pause_idle_dags(dags = ["myTutorial"]):
    """
    Pauses dags from the airflow
    :param dags: dags considered to be idle
    :return: Success state
    """
    # TODO
    for dag in dags:
        command = "airflow pause {}".format(dag)
        print(executeBashCommand(command))

def executeBashCommand(command):
    print('========RUN========', command)
    p = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = p.communicate()
    if p.returncode != 0:
        print('========STDOUT========\n',stdout.decode())
        print('========STDERR========\n',stderr.decode())
        raise Exception('There is error while executing bash command: '+command+'\nwith log:\n'+stderr.decode())
    return stdout, stderr

1 个答案:

答案 0 :(得分:0)

当运行指示其执行某些操作的气流命令时,它应编辑与其连接的后端数据库的内部状态。默认情况下使用SQLite进行通风。您可能已经设置了自己的一个。无论哪种方式,您都可以查询以进行检查。

例如airflow=# select * from dag where is_paused;

在这里,您显然还可以执行更新,例如

airflow=# update dag set is_paused='false' where is_paused;