如何在SmartSensor中使用气流执行日期?

2024-09-25 18:19:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图使用SmartSensors实现ExternalTaskSensor,但由于它使用execution_date来戳其他DAG状态,我似乎无法通过它,如果我从SmartExternalSensor中省略它,它会说有一个KeyError和执行日期,因为它不存在

我试图重写get_poke_context方法

    def get_poke_context(self, context):
        result = super().get_poke_context(context)

        if self.execution_date is None:
            result['execution_date'] = context['execution_date']

        return result

但它现在表示datetime对象不可json序列化(这是在使用json.dumps将传感器注册为SmartSensor时完成的),并作为普通传感器运行。如果我直接传递datetime对象的字符串,它表示str object has no isoformat() method,因此我知道执行日期必须是datetime对象

你们知道怎么解决这个问题吗


Tags: 对象selfjsongetdatetimedate状态context