Atomic transaction aware Celery tasks for Django 1.6+
Project description
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:
on Django >= 1.9, use the built-in on_commit hook
on Django < 1.9, use django-transaction-hooks (the original source of 1.9’s on_commit)
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
Hashes for django-atomic-celery-1.1.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b27cc43b1d0bc071bd52bff4f5196cf6028eea28e09125b44ae882b0868b92d |
|
MD5 | 091b634bff940922dd8569356e464569 |
|
BLAKE2b-256 | 887e581605b9a4a67362d463754414fcb128a73760b9cb802d01e0deda01cd88 |