Extend the base :class:`~celery.app.task.Task` for Django. Provide a nicer API to trigger tasks at the end of the DB transaction.
| 6 | |
| 7 | |
| 8 | class DjangoTask(Task): |
| 9 | """ |
| 10 | Extend the base :class:`~celery.app.task.Task` for Django. |
| 11 | |
| 12 | Provide a nicer API to trigger tasks at the end of the DB transaction. |
| 13 | """ |
| 14 | |
| 15 | def delay_on_commit(self, *args, **kwargs) -> None: |
| 16 | """Call :meth:`~celery.app.task.Task.delay` with Django's ``on_commit()``.""" |
| 17 | transaction.on_commit(functools.partial(self.delay, *args, **kwargs)) |
| 18 | |
| 19 | def apply_async_on_commit(self, *args, **kwargs) -> None: |
| 20 | """Call :meth:`~celery.app.task.Task.apply_async` with Django's ``on_commit()``.""" |
| 21 | transaction.on_commit(functools.partial(self.apply_async, *args, **kwargs)) |