- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
有谁知道在 bash 提示符下运行 airflow test
时是否可以设置 dag_run.conf 参数?
例如,我下载了 example_trigger_target_dag来自官方 Airflow 存储库,我想测试 run_this
任务。通常我会做以下事情:
~/$ Airflow 测试 example_trigger_target_dag run_this '2018-01-01'
但是运行它会产生错误:
--------------------------------------------------------------------------------
Starting attempt 1 of 1
--------------------------------------------------------------------------------
[2018-05-02 10:50:01,154] {models.py:1342} INFO - Executing <Task(PythonOperator): run_this> on 2018-01-01 00:00:00
[2018-05-02 10:50:01,262] {models.py:1417} ERROR - 'NoneType' object has no attribute 'conf'
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/airflow/models.py", line 1374, in run
result = task_copy.execute(context=context)
File "/usr/local/lib/python2.7/dist-packages/airflow/operators/python_operator.py", line 80, in execute
return_value = self.python_callable(*self.op_args, **self.op_kwargs)
File "/home/annalect/uk_ds_airflow/dags/playpen/example_trigger_target_dag.py", line 56, in run_this_func
print("Remotely received value of {} for key=message".format(kwargs['dag_run'].conf['message']))
AttributeError: 'NoneType' object has no attribute 'conf'
我尝试过使用 task_params
参数,但是我的语法错误或者它没有实现我想要的,因为它产生了与上面相同的错误:
~/$ airflow test --task_params '{"kwargs": {"dag_run": {"conf": {"message": "Hey world"}}}}' example_trigger_target_dag run_this '2018-01 -01'
[2018-05-02 11:10:58,065] {models.py:1441} INFO - Marking task as FAILED.
[2018-05-02 11:10:58,070] {models.py:1462} ERROR - 'NoneType' object has no attribute 'conf'
那么有人知道如何测试依赖于 dag_run.conf
值的任务吗?
谢谢!
最佳答案
airflow test
命令没有 --conf
选项,但您可以通过将参数传递给任务的 python_callable
来解决此问题。
在 callable 中,如果设置了 kwargs['test_mode']
,您可以检索参数以构建一个虚拟的 DagRun
对象,如下所示:
from airflow.models import DagRun
...
def run_this_func(ds, **kwargs):
if kwargs['test_mode']:
kwargs['dag_run'] = DagRun(conf=kwargs['params'])
print("Remotely received value of {} for key=message".format(kwargs['dag_run'].conf['message']))
要测试 example_trigger_target_dag
,只需执行以下操作:
airflow test example_trigger_target_dag test_trigger_dagrun "2018-01-01" -tp '{"message":"Hello world"}'
你会得到:
Remotely received value of Hello world for key=message
现在您可以编写一个装饰器,而不是将测试代码放入您的任务中。此外,由于我们只是使用 DagRun
的 conf
属性,我们也可以使用 SimpleNamespace
。最后,为了避免在查找 kwargs
时出现潜在的键错误,我们可以使用带有默认值的 get
。
from types import SimpleNamespace
def allow_conf_testing(func):
def wrapper(*args, **kwargs):
if kwargs.get('test_mode', False):
kwargs['dag_run'] = SimpleNamespace(conf=kwargs.get('params', {}))
func(*args, **kwargs)
return wrapper
@allow_conf_testing
def run_this_func(ds, **kwargs):
print("Remotely received value of {} for key=message".format(kwargs['dag_run'].conf['message']))
关于python - 在调用 Airflow 测试时设置 dag_run.conf 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50132215/
我在play官方网站上关注了“Learn”。我使用的是window 7+Chrome。 D:\tester\play>dir Volume in drive D is APPLIS Volum
我有一个 play 1.2.5 应用程序,想将它部署到某个地方(这样我就可以为一些 OAuth 回调注册它)。我正在尝试将其推送到 heroku,但出现以下错误 -----> Play! app de
周围有两个配置文件,/etc/nginx/conf.d/default.conf和 /etc/nginx/nginx.conf,但是启用了哪一个呢?我运行的是 CentOS6.4 和 nginx/1.
我已经在Flume 1.6.0-cdh5.4.2(CentOS)中安装了cloudera VM 我认为配置和一切都很好 我运行了以下命令槽 flume-ng --conf /conf agent -
为了避免对我本地托管的 apache-tomcat Web 服务器上托管的 Web 应用程序进行点击劫持攻击,我正在尝试编辑“httpd.conf”文件以向其附加 X 选项。 用“sudo nano/
当我想为 intel Galileo 构建一个 yocto 镜像时,我按照网站中提到的这些说明进行操作 https://software.intel.com/en-us/blogs/2015/03/0
如果我有一个名为 mysite.conf 的文件存储在 /etc/nginx/conf.d .有没有办法获取字符串值'mysite'从conf文件中? 我想多次符号链接(symbolic link)一
为大学生编写一个应用程序——显示一个系列表,你点击一个,然后它会显示该系的类(class),点击一个,然后显示教授该类(class)的教授。 URL conf 有问题——我的应用程序不断将我重定向到错
当试图启动 apache 时 sudo /etc/init.d/apache2 restart 我得到了错误 apache2: Syntax error on line 260 of /etc/apa
我关注 this tutorial我找不到本教程第二步的 phpmyadmin.conf。我在/etc/apache2/conf-available/中只有以下文件 charset.conf othe
httpd.conf(/etc/httpd/conf/httpd.conf) 和 ssl.conf(/etc/httpd/conf.d/ssl.conf) 有什么区别 文件? 我正在尝试在我的站点上设
所有配置都被包含在内,并且 conf 测试也通过了。但是 Nginx 仍然提供来自 /usr/share/nginx/html 的默认 HTML。 , 而不是 conf.d 目录中 conf 文件的位
我是 psql 的新手,我遇到了一些我认为是错误放置的 .conf 文件引起的问题。当我尝试登录我之前创建的数据库时出现错误 $ psql corporation psql: could not co
我在 /etc/httpd/conf.d/vhost.conf 中的虚拟主机配置如下所示: NameVirtualHost * ServerName www.example.com
我遵循了教程:http://www.webopius.com/content/355/getting-mamp-working-with-ssl-on-os-x获取 ssl 证书。但是,我无法在 st
是否有一个 spark 属性,我们可以在执行 spark 提交时设置它指定 hadoop 配置路径,专门指向自定义 hdfs-site.xml 和 core-site.xml 文件 最佳答案 首选的方
在NameNode和JobTracker不是同一台服务器的hadoop集群(1.x版本)中,conf/masters和conf/slaves是需要在NameNode和JobTracker上同时指定还是
我从 Here 下载 Redis-x64-3.2.100.zip ,当我提取它时,我看到两个文件 redis.windows.conf 和 redis.windows-service.conf,我比较
我目前正在检查我们的 JBoss AS7.1 服务器配置,我在我们的 jboss/standalone/bin 目录中发现了这两个以前配置的文件: standalone.conf standalone
我一直在使用这个教程http://mpjexpress.blogspot.co.nz/2010/05/executing-and-debugging-mpj-express.html 、文本:步骤 1
我是一名优秀的程序员,十分优秀!