I would like to pause DAGs that are idle and redundant, How do I know which DAGs are unpaused and which are paused?
So I have a list of DAGs that are to be unpaused using a bashcommand that executes 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. I've checked the airflow webserver and it seems that all of my paused DAGs are still running.
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