django-celery-transactions

Django transaction support for Celery tasks.

  • 所有者: bradleyayers/django-celery-transactions
  • 平台:
  • 许可证: Other
  • 分类:
  • 主题:
  • 喜欢:
    0
      比较:

Github星跟踪图

django-celery-transactions

django-celery-transactions holds on to Celery tasks until the current database
transaction is committed, avoiding potential race conditions as described in
Celery's user guide. Send tasks from signal handlers without fear!

Features

  • If the transaction is rolled back, the tasks are discarded. Django's
    transaction middleware does this if an exception is raised.
  • If transactions aren't being managed, tasks are sent as normal. This means
    that sending tasks from within Django's shell will work as expected, as will
    the various transaction decorators commit_manually, commit_on_success, etc.

Installation & Use

  1. Install django-celery-transactions from PyPI:

     $ pip install django-celery-transactions
    
  2. Use the patched decorator to create your tasks:

     from djcelery_transactions import task
     from models import Model
    
    
     @task
     def print_model(model_pk):
         print Model.objects.get(pk=model_pk)
    
  3. Then use them as normal:

     from django.db import transaction
     from models import Model
     from tasks import print_model
    
    
     # This task will be sent after the transaction is committed. This works
     # from anywhere in the managed transaction block (e.g. signal handlers).
     def view(request):
         model = Model.objects.create(...)
         print_model.delay(model.pk)
    
    
     # This task will not be sent (it is discarded) as the transaction
     # middleware rolls the transaction back when it catches the exception.
     def failing_view(request, model_pk):
         print_model.delay(model_pk)
         raise Exception()
    
    
     # This task will be sent immediately as transactions aren't being
     # managed and it is assumed that the author knows what they're doing.
     @transaction.commit_manually
     def manual_view(request, model_pk):
         print_model.delay(model_pk)
         transaction.commit()
    

Run test suite

    $ python setup.py test

主要指标

概览
名称与所有者bradleyayers/django-celery-transactions
主编程语言Python
编程语言Python (语言数: 1)
平台
许可证Other
所有者活动
创建于2012-01-27 10:51:29
推送于2021-12-14 21:20:08
最后一次提交2012-12-14 12:57:50
发布数0
用户参与
星数194
关注者数9
派生数55
提交数19
已启用问题?
问题数9
打开的问题数6
拉请求数2
打开的拉请求数6
关闭的拉请求数1
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?