【发布时间】:2022-11-13 20:20:57
【问题描述】:
我在 Airflow 中制作了一个自定义传感器,它继承了BashSensor。
传感器 :
class MySensor(BashSensor):
def __init__(self, time, **kwargs): # {{ ts }} is passed as time in the DAG
self.time = time
cmd = f"java some-other-stuff {self.time}" # rendered/correct value for self.time
super().__init__(**kwargs, bash_command=cmd)
def poke(self, context):
status = super().poke() # returns True or False
if status:
print(self.time) # {{ ts }} is printed instead of rendered value
else:
print("trying again")
return status
当我查看 DAG 中操作员任务的渲染选项卡时,我看到 bash_command 具有正确的渲染值({{ ts }} 作为 time 传递)。
问题是每当调用 poke 并返回 True 时,我在 print 语句中看到 {{ ts }} 而不是呈现的值。
当我在poke 函数中打印它时,我希望self.time 具有呈现的值(一些时间戳)而不是{{ ts }}。
【问题讨论】: