[英]How to validate airflow DAG with customer operator?
The airflow docs suggest that a basic sanity check for a DAG file is to interpret it. 气流文档建议对DAG文件进行基本的完整性检查以解释该文件。 ie:
即:
$ python ~/path/to/my/dag.py
I've found this to be useful. 我发现这很有用。 However, now I've created a plugin,
MordorOperator
under $AIRFLOW_HOME/plugins
: 但是,现在我已经在
$AIRFLOW_HOME/plugins
下创建了一个插件MordorOperator
:
from airflow.plugins_manager import AirflowPlugin from airflow.utils.decorators import apply_defaults from airflow.operators import BaseOperator from airflow.exceptions import AirflowException import pika import json class MordorOperator(BaseOperator): JOB_QUEUE_MAPPING = {"testing": "testing"} @apply_defaults def __init__(self, job, *args, **kwargs): super().__init__(*args, **kwargs) # stuff def execute(self, context): # stuff class MordorPlugin(AirflowPlugin): name = "MordorPlugin" operators = [MordorOperator]
I can import the plugin and see it work in a sample DAG: 我可以导入插件,并在示例DAG中查看它的工作方式:
from airflow import DAG from airflow.operators import MordorOperator from datetime import datetime dag = DAG('mordor_dag', description='DAG with a single task', start_date=datetime.today(), catchup=False) hello_operator = MordorOperator(job="testing", task_id='run_single_task', dag=dag)
However, when I try to interpret this file I get failures which I suspect I shouldn't get since the plugin successfully runs. 但是,当我尝试解释此文件时,会出现失败,我怀疑由于插件成功运行,我不应该失败。 My suspicion is that this is because there's some dynamic code gen happening at runtime which isn't available when a DAG is interpreted by itself.
我怀疑这是因为在运行时发生了一些动态代码生成,而当DAG本身被解释时,这些动态代码生成将不可用。 I also find that PyCharm can't perform any autocompletion when importing the plugin.
我还发现,导入插件时,PyCharm无法执行任何自动补全。
(venv) 3:54PM /Users/paymahn/solvvy/scheduler mordor.operator ✱ ❮❮❮ python dags/mordor_test.py section/key [core/airflow-home] not found in config Traceback (most recent call last): File "dags/mordor_test.py", line 2, in from airflow.operators import MordorOperator ImportError: cannot import name 'MordorOperator'
How can a DAG using a plugin be sanity tested? 使用插件的DAG如何进行完整性测试? Is it possible to get PyCharm to give autocompletion for the custom operator?
是否有可能让PyCharm为自定义运算符提供自动补全功能?
I'm running airflow in a docker container and have a script which runs as the containers entry point. 我在Docker容器中运行气流,并有一个脚本作为容器入口点运行。 Turns out that the
plugins
folder wasn't available to my container when I was running my tests. 事实证明,运行测试时,我的容器无法使用
plugins
文件夹。 I had to add a symlink in the container as part of the setup script. 作为安装脚本的一部分,我必须在容器中添加一个符号链接。 The solution to my problem is highly specific to me and if someone else stumbles upon this I don't have a good answer for your situation other than: make sure your plugins folder is correctly available.
解决我的问题的方法对我来说是高度特定的,如果其他人偶然发现了该问题,除了您无法确保您的情况之外,我没有一个很好的答案:确保您的plugins文件夹正确可用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.