'how to check that particular dag is present in dag bucket or not

we have requirement that we are using one DAG to trigger another DAG, now here we want to place one check that if DAG is present in airflow then only trigger it else ignore. so is there any way to check that DAG is present or not?

we have tried to find something related DAGBAG but not getting much

update: from airflow.models import DagBag

def my_poc(**kwargs): dagbag = DagBag(None, False, False, True, True)

dags=['my_test_dag1','my_test_dag2']
for dag in dags:
    try:
        dag_class = dagbag.get_dag(dag)
        print(dag,' is present in bucket')
    except:
        print(dag,' is not present in bucket')

i have tried this and its working as expected but is there any better way to do it



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source