This document describes the current stable version of Celery (5.4). For development docs, go here.

Source code for celery.contrib.django.task

import functools

from django.db import transaction

from import Task

[docs] class DjangoTask(Task): """ Extend the base :class:`` for Django. Provide a nicer API to trigger tasks at the end of the DB transaction. """
[docs] def delay_on_commit(self, *args, **kwargs) -> None: """Call :meth:`` with Django's ``on_commit()``.""" transaction.on_commit(functools.partial(self.delay, *args, **kwargs))
[docs] def apply_async_on_commit(self, *args, **kwargs) -> None: """Call :meth:`` with Django's ``on_commit()``.""" transaction.on_commit(functools.partial(self.apply_async, *args, **kwargs))