气流默认on

编程入门 行业动态 更新时间:2024-10-17 02:58:50
本文介绍了气流默认on_failure_callback的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在我的DAG文件中,我定义了一个on_failure_callback()函数以在失败时发布Slack.

In my DAG file, I have define a on_failure_callback() function to post a Slack in case of failure.

如果我在DAG中为每个运算符指定一个,它将很好地工作:on_failure_callback = on_failure_callback()

It works well if I specify for each operator in my DAG : on_failure_callback=on_failure_callback()

是否有一种方法可以自动(例如通过default_args或通过我的DAG对象)将调度分配给我所有的运算符?

Is there a way to automate (via default_args for instance, or via my DAG object) the dispatch to all of my operators?

推荐答案

我终于找到了一种方法.

I finally found a way to do that.

您可以将on_failure_callback作为default_args传递

You can pass your on_failure_callback as a default_args

class Foo: @staticmethod def get_default_args(): """ Return default args :return: default_args """ default_args = { 'on_failure_callback': Foo.on_failure_callback } return default_args @staticmethod def on_failure_callback(context): """ Define the callback to post on Slack if a failure is detected in the Workflow :return: operator.execute """ operator = SlackAPIPostOperator( task_id='failure', text=str(context['task_instance']), token=Variable.get("slack_access_token"), channel=Variable.get("slack_channel") ) return operator.execute(context=context)

更多推荐

气流默认on

本文发布于:2023-11-23 19:03:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622544.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:气流

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!