Created
October 8, 2016 03:56
-
-
Save tapanpandita/46d2e2f63c7425547a865cb6298a172f to your computer and use it in GitHub Desktop.
Transaction aware celery abstract task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TransactionAwareTask(Task): | |
''' | |
Task class which is aware of django db transactions and only executes tasks | |
after transaction has been committed | |
''' | |
abstract = True | |
def apply_async(self, *args, **kwargs): | |
''' | |
Unlike the default task in celery, this task does not return an async | |
result | |
''' | |
transaction.on_commit( | |
lambda: super(TransactionAwareTask, self).apply_async( | |
*args, **kwargs)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I would like to contribute with some few code lines, the idea is to make it work with transactional and not transactional tests