-
-
Save antonioj-mattos/27bd6172258da2eea615b61ab5e124e8 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