Created
January 22, 2014 14:48
-
-
Save mwieher/8559971 to your computer and use it in GitHub Desktop.
Django 1.4, Celery Camera, Integration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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