Skip to content

Instantly share code, notes, and snippets.

@antonioj-mattos
Forked from tapanpandita/celery.py
Created February 7, 2020 03:06
Show Gist options
  • Save antonioj-mattos/27bd6172258da2eea615b61ab5e124e8 to your computer and use it in GitHub Desktop.
Save antonioj-mattos/27bd6172258da2eea615b61ab5e124e8 to your computer and use it in GitHub Desktop.
Transaction aware celery abstract task
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