This question was originally posted on GitHub under: https://github.com/Bogdanp/dramatiq/issues/93
thank you for the hints and tried some of them, especially the results but I am still not happy with my result.
Let me describe you how what I want to achieve:
- I sent a Message via an Actor with message = add.send(1, 2) - from there I get back an message_id from the broker
- I want to store this message_id e.g. in a MySQL database before it is accessible with message.get_result(backend=backend) --> Here I do not know if any of the Middleware functions are of any help for this use case
- If 1 and 2 are in place, I can distinguish between an existing message/task and a non-existing one, by querying the database.
- Further I can update the status of the message/task in the database over the time of the process.
Answer from @bogdan:
To answer your question, though, this is possible via middleware. You can check out the
django_dramatiq for an example.
I checked it out but this seems to be very tightly integrated into django, is it possible to adapt the behavior also to Flask?
Question for usage of this in django_dramatiq_example
How can I use the
task class from django_dramatiq
in the django example provided, so using the variables that stores my function result into
id = models.UUIDField(primary_key=True, editable=False) status = models.CharField(max_length=8, choices=STATUSES, default=STATUS_ENQUEUED) created_at = models.DateTimeField(auto_now_add=True) updated_at = models.DateTimeField(auto_now=True) message_data = models.BinaryField()
to use with for example a MySQL DB, because these seem to be overwritten with
class Job(models.Model) in the provided example.