Skip to content

Instantly share code, notes, and snippets.

@mwieher
Created January 22, 2014 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwieher/8559971 to your computer and use it in GitHub Desktop.
Save mwieher/8559971 to your computer and use it in GitHub Desktop.
Django 1.4, Celery Camera, Integration
from djcelery.snapshot import Camera
from django.db import transaction
class CustomCam(Camera):
def on_shutter(self, state, commit_every=100):
if not state.event_count:
if transaction.is_managed():
transaction.commit()
return
def _handle_tasks():
for i, task in enumerate(state.tasks.items()):
self.handle_task(task)
if not i % commit_every:
if transaction.is_managed():
transaction.commit()
for worker in state.workers.items():
self.handle_worker(worker)
_handle_tasks()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment