'How to prevent queueing Dramatiq tasks until Django transaction is committed?
I'm currently using Celery but I'm seriously considering migrating to Dramatiq (and django-dramatiq) because of how much simpler things could be. Celery just seems overly complicated (especially for my usecases) and not all that reliable.
However, one feature of Celery I use is the option to add a base class for each task. I add a TransactionAwareTask as a base class for most tasks (inspired by this blog post).
This base class holds the task (when calling apply_async) and only actually sends it to the queue when transaction.on_commit is reached, meaning that the surrounding transaction succeeded and the task can safely be queued.
This way, I will (for instance) never send an email to a client when their action actually failed. And the task will never run before the transaction is committed (which technically could happen if somehow the process was slower than the task queue).
Is there a way to do this with Dramatiq? It seems dramatiq middleware might be useful (and I could turn it off for testing where transactions are not committed at all) but I'm not quite sure. Has anyone done something like this?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
