[英]How can I get `ds` in SlackAPIPostOperator?
I want to run a python script which need a datetime param and post its output to slack. 我想运行一个需要datetime参数的python脚本,并将其输出发布到松弛状态。 But I don't know how to get airflow template variable ds
. 但是我不知道如何获取气流模板变量ds
。
Let's say, I have below code: 假设我有以下代码:
def make_txt():
# get ds
ds = get_ds()
ds = ds * 3 + 4 / 5 # do something with ds
return ds
slack_task = SlackAPIPostOperator(
text=make_txt(),
token='xoxp-xxxxxxx',
)
Because I will run with airflow backfill dag_id -s 2016-10-01
, the ds
(here is 2016-10-01) should pass to slack text. 因为我将使用airflow backfill dag_id -s 2016-10-01
来运行,所以ds
(此处为2016-10-01)应该传递给松弛文本。
I try to write python script output to a file and then read it and pass to slack text directly. 我尝试将python脚本输出写入文件,然后读取它并直接传递给松弛文本。 But I don't think that's a perfect solution. 但是我认为这不是一个完美的解决方案。
SlackAPIPostOperator
的text
字段是模板化的,因此,如果在文本中的某处添加{{ ds }}
,它将由jinja插入。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.