0

When working with dramatiq 1.9.0 (flask-dramatiq 0.6.0) I'm unable to call on_success- or on_failure-callbacks. The official dramatiq-documentation states callbacks can be used like this:

@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)

However, I'm getting the following error:

ERROR - on_failure value must be an Actor

In .../site-packages/dramatiq/actor.py there is

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")

which shows that the callback isn't from the type Actor but flask-dramatiqs LazyActor.

If I import the original package with import dramatiq as _dramatiq and change the decorator to _dramatiq.actor, nothing happens at all. The task won't start.

How do I define callbacks in flask-dramatiq?

Kruspe
  • 626
  • 6
  • 19

0 Answers0