0

使用dramatiq 1.9.0( flask-dramatiq 0.6.0) 时,我无法调用on_success- 或 -on_failure回调。官方的Dramatiq-documentation状态回调可以这样使用:

@dramatiq.actor
def taskFailed(message_data, exception_data):
    print("Task failed")

@dramatiq.actor
def taskSucceeded(message_data, result):
    print("Success")

dramatiqTask.send_with_options(args=(1, 2, 3), on_success=taskSucceeded, on_failure=taskFailed)

但是,我收到以下错误:

ERROR - on_failure value must be an Actor

.../site-packages/dramatiq/actor.py里面有

def message_with_options(self, *, args=None, kwargs=None, **options):
    for name in ["on_failure", "on_success"]:
        callback = options.get(name)
        print(str(type(callback))) # Returns "<class 'flask_dramatiq.LazyActor'>"
        if isinstance(callback, Actor):
            options[name] = callback.actor_name

        elif not isinstance(callback, (type(None), str)):
            raise TypeError(name + " value must be an Actor")

这表明回调不是来自类型Actor,而是来自 flask-dramatiqs LazyActor

如果我导入原始包import dramatiq as _dramatiq并将装饰器更改为_dramatiq.actor,则什么也不会发生。任务不会开始。

如何在 中定义回调flask-dramatiq

4

0 回答 0