简体   繁体   English

如何确定 DAG 在 Airflow 中是否暂停/取消暂停?

[英]How can I find out if a DAG is paused/unpaused in Airflow?

I would like to pause DAGs that are idle and redundant, How do I know which DAGs are unpaused and which are paused?我想暂停空闲和冗余的 DAG,我如何知道哪些 DAG 未暂停,哪些已暂停?

So I have a list of DAGs that are to be unpaused using a bashcommand that executes airflow pause <dag_id> .所以我有一个 DAG 列表,这些 DAG 将使用执行airflow pause <dag_id>的 bashcommand 取消airflow pause <dag_id> I would like to know if the command is successful or not by checking the state of pause of each DAGs.我想通过检查每个 DAG 的pause状态来知道命令是否成功。 I've checked the airflow webserver and it seems that all of my paused DAGs are still running.我检查了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

When you run airflow commands that instruct it to perform some action it should edit the internal stat of the backend database that it is connected to.当您运行指示它执行某些操作的气流命令时,它应该编辑它所连接的后端数据库的内部统计信息。 By default airflow using SQLite.默认情况下气流使用 SQLite。 You may have setup your own one.您可能已经设置了自己的一个。 Either way you can query that to check.无论哪种方式,您都可以查询以进行检查。

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

Here you can obviously also perform updates such as在这里,您显然还可以执行更新,例如

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM