简体   繁体   English

DAG 在 Airflow UI 上不可见

[英]DAG is not visible on Airflow UI

This is my dag file in dags folder.这是我在dags文件夹中的 dag 文件。

Code that goes along with the Airflow located at:
http://airflow.readthedocs.org/en/latest/tutorial.html
"""
from airflow import DAG
from airflow.operators.dummy_operator import DummyOperator
from airflow.operators.python_operator import PythonOperator
from datetime import datetime, timedelta
from work_file import Test


class Main(Test):
    def __init__(self):
        super(Test, self).__init__()

    def create_dag(self):
        default_args = {
            "owner": "airflow",
            "depends_on_past": False,
            "start_date": datetime(2015, 6, 1),
            "email": ["airflow@airflow.com"],
            "email_on_failure": False,
            "email_on_retry": False,
            "retries": 1,
            "retry_delay": timedelta(minutes=5),
            # 'queue': 'bash_queue',
            # 'pool': 'backfill',
            # 'priority_weight': 10,
            # 'end_date': datetime(2016, 1, 1),
        }
        dag = DAG("python_dag", default_args=default_args, schedule_interval='0 * * * *')

        dummy_task = DummyOperator(task_id='dummy_task', retries=3)

        python_task = PythonOperator(task_id='python_task', python_callable=self.my_func)

        dummy_task >> python_task


if __name__ == "__main__":
    a = Main()
    a.create_dag()

This is my other file work_file.py which is in the same dags folder.这是我在同一个dags文件夹中的另一个文件work_file.py

class Test:
    def __init__(self):
        pass

    def my_func(self):
        return "Hello"

Aim :-The Aim is to call the my_func from my dag file.目标:-目标是从我的 dag 文件中调用my_func

Problem :- There seems to be no error on the UI,but my dag python_dag is not visible.问题:- UI 上似乎没有错误,但我的 dag python_dag不可见。

My server, scheduler is also running, I've tried restarting the same but nothing happened.我的服务器,调度程序也在运行,我尝试重新启动相同但没有任何反应。

I have imported the file as well ( from work_file import Test )我也导入了文件( from work_file import Test

Thanks in advance!提前致谢!

There are multiple problems with the DAG: DAG 存在多个问题:

  1. The operators are not assigned to any DAG.运算符未分配给任何 DAG。 Add dag=dag to the constructors.dag=dag添加到构造函数中。 Eg, DummyOperator(..., dag=dag) .例如, DummyOperator(..., dag=dag)
  2. create_dag() does not return the DAG. create_dag()不返回 DAG。 Add return dag .添加return dag
  3. The DAG script is not executed as the top level code. DAG 脚本不作为顶级代码执行。 That is, the modules __name__ is never '__main__' .也就是说,模块__name__永远不是'__main__' Remove if __name__ == "__main__": .删除if __name__ == "__main__":
  4. The DAG objects must be in the global namespace of the module. DAG 对象必须位于模块的全局命名空间中。 Assign the return value of create_dag() to a variable: dag = a.create_dag() .create_dag()的返回值分配给一个变量: dag = a.create_dag()

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

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