From 2d36ca047e1415fcc960e2b4d5dfe1f05eb2c284 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Mon, 2 Jan 2012 17:58:26 +0530 Subject: [PATCH] dispatch stream update to celery --- .../management/commands/import_streams.py | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/pandora/archive/management/commands/import_streams.py b/pandora/archive/management/commands/import_streams.py index 06ecfa434..92c909036 100644 --- a/pandora/archive/management/commands/import_streams.py +++ b/pandora/archive/management/commands/import_streams.py @@ -5,9 +5,32 @@ from django.conf import settings import os from glob import glob +from celery.task import task + from ... import models, extract +@task(queue="encoding") +def update_stream(id): + s = models.Stream.objects.get(pk=id) + if not glob("%s*"%s.timeline_prefix): + s.make_timeline() + if not s.color: + s.cuts = tuple(extract.cuts(s.timeline_prefix)) + s.color = tuple(extract.average_color(s.timeline_prefix)) + s.save() + + s.file.selected = True + s.file.save() + s.file.item.update_timeline() + #make sure all derivatives exist + s.extract_derivatives() + + #update clips + for c in s.file.item.clips.all(): + c.update_calculated_values() + c.save() + class Command(BaseCommand): """ """ @@ -49,20 +72,4 @@ class Command(BaseCommand): s.save() print "update streams" for s in models.Stream.objects.filter(source=None): - if not glob("%s*"%s.timeline_prefix): - s.make_timeline() - if not s.color: - s.cuts = tuple(extract.cuts(self.timeline_prefix)) - s.color = tuple(extract.average_color(self.timeline_prefix)) - s.save() - - s.file.selected = True - s.file.save() - s.file.item.update_timeline() - #make sure all derivatives exist - s.extract_derivatives() - - #update clips - for c in s.file.item.clips.all(): - c.update_calculated_values() - c.save() + update_stream.delay(s.id)