我似乎不明白如何将模块导入到apache airflow DAG定义文件中.我想这样做是为了能够创建一个库,例如,使用相似的设置声明任务更简洁.
这是我能想到的最简单的例子,它复制了这个问题:我修改了气流教程(https://airflow.apache.org/tutorial.html#recap),只需导入一个模块并从该模块运行一个定义.像这样:
目录结构:
- dags/
-- __init__.py
-- lib.py
-- tutorial.py
Run Code Online (Sandbox Code Playgroud)
tutorial.py:
"""
Code that goes along with the Airflow located at:
http://airflow.readthedocs.org/en/latest/tutorial.html
"""
from airflow import DAG
from airflow.operators.bash_operator import BashOperator
from datetime import datetime, timedelta
# Here is my added import
from lib import print_double
# And my usage of the imported def
print_double(2)
## -- snip, because this is just the tutorial code,
## i.e., some standard DAG defintion stuff --
Run Code Online (Sandbox Code Playgroud)
print_double 只是一个简单的def,它将你给它的任何输入乘以2,并打印结果,但显然这甚至不重要,因为这是一个导入问题. …