Skip to main content

Atomic transaction aware Celery tasks for Django 1.6+

Project description

https://travis-ci.org/adamchainz/django_atomic_celery.png?branch=master

Don’t Use This Library

This library uses django-atomic-signals. Unfortunately this is not a great way of achieving “don’t run this code until the transaction commits” any more. There is plenty of extra description on django-atomic-signals’ README, and also on the similar library django-transaction-signals, by Django core developer Aymeric.

If you want a supported method of executing a celery task on commit, then:

Both give examples with celery tasks so you are in good hands.

If your project is still using this library, please migrate. You will need to remove django-atomic-signals as well as django-atomic-celery. A new, “don’t use me” version that breaks on import will be pushed soon to PyPI to propagate this warning.

Old Readme Continues

django_atomic_celery provides a Django 1.6-1.7 compatible approach to transactionally aware Celery task scheduling.

To install django_atomic_celery, do yourself a favor and don’t use anything other than pip:

$ pip install django-atomic-celery

Add django_atomic_celery along with its dependency, django_atomic_signals, to the list of installed apps in your settings file:

INSTALLED_APPS = (
    'django_atomic_signals',
    'django_atomic_celery',
    ..
)

Usage

Using django_atomic_celery is exactly like using Celery the way you normally would. However, instead of importing Celery’s variant of the task decorator, import it from django_atomic_celery:

from django_atomic_celery import task


@task
def simple_task():
    ..


@task(ignore_result=True, max_retries=3, default_retry_delay=10)
def retrying_task(arg):
    ..

If you use Celery 3.1 and its internal integration of Django, you can choose to instantiate your Celery app providing the atomic task class as the task_cls argument to have all tasks be atomic transaction aware. Based on an example from the Celery documentation this is done as follows:

from celery import Celery

..
app = Celery('proj', task_cls='django_atomic_celery:PostTransactionTask')
..

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-atomic-celery-1.1.2.tar.gz (4.6 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page