From bf9a91280e73ac20b33daa46348d476738e0ec21 Mon Sep 17 00:00:00 2001 From: j <0x006A@0x2620.org> Date: Sat, 23 Jan 2010 10:25:48 +1100 Subject: [PATCH] another background script: encoder --- oxdb/backend/admin.py | 3 -- oxdb/backend/daemon.py | 4 +- oxdb/backend/encoder.py | 43 +++++++++++++++++++ .../management/commands/backgroundtasks.py | 8 ++-- oxdb/backend/models.py | 4 ++ 5 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 oxdb/backend/encoder.py diff --git a/oxdb/backend/admin.py b/oxdb/backend/admin.py index 2341c9c9..fa1d2f08 100644 --- a/oxdb/backend/admin.py +++ b/oxdb/backend/admin.py @@ -1,6 +1,5 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 -# Written 2009 by j@mailb.org from django.contrib import admin @@ -25,7 +24,6 @@ class MovieAdmin(admin.ModelAdmin): admin.site.register(models.Movie, MovieAdmin) - class FileAdmin(admin.ModelAdmin): search_fields = ['path', 'video_codec'] @@ -39,7 +37,6 @@ class ArchiveFileAdmin(admin.ModelAdmin): admin.site.register(models.ArchiveFile, ArchiveFileAdmin) - class ArchiveAdmin(admin.ModelAdmin): search_fields = ['name'] admin.site.register(models.Archive, ArchiveAdmin) diff --git a/oxdb/backend/daemon.py b/oxdb/backend/daemon.py index d1a710cf..c7ea2892 100644 --- a/oxdb/backend/daemon.py +++ b/oxdb/backend/daemon.py @@ -19,10 +19,10 @@ def run(): exchange="oxdb-bg", routing_key="oxdb-bg") def handle_background_tasks_callback(data, message): - print("Got feed import message") + print("Got bg message") print data if 'loadIMDb' in data: - imdbId = message_data['loadIMDb'] + imdbId = data['loadIMDb'] load.loadIMDb(imdbId) elif 'findMovie' in data: f = models.File.objects.get(pk=data['findMovie']) diff --git a/oxdb/backend/encoder.py b/oxdb/backend/encoder.py new file mode 100644 index 00000000..d588e6a6 --- /dev/null +++ b/oxdb/backend/encoder.py @@ -0,0 +1,43 @@ +from carrot.connection import DjangoBrokerConnection +from carrot.messaging import Consumer, Publisher +from django.conf import settings + +import load +import models + +def send_encoder_message(msg): + conn = DjangoBrokerConnection() + publisher = Publisher(connection=conn, exchange="oxdb-encoder", + routing_key="oxdb-encoder") + publisher.send(msg) + publisher.close() + +def run(): + conn = DjangoBrokerConnection() + + consumer = Consumer(connection=conn, queue="oxdb-encoder", + exchange="oxdb-encoder", + routing_key="oxdb-encoder") + def handle_background_tasks_callback(data, message): + print("Got encoder message") + print data + if 'extract' in data: + ''' + update file stuff + create derivates and other related stuff for a file + ''' + fileId = data['fileId'] + f = models.File.objects.get(pk=fileId) + f.extract() + elif 'updateMovie' in data: + ''' + update movie + create proxy stream and other related files extracted from movieFiles + ''' + movieId = data['movieId'] + m = models.Movie.objects.get(pk=fileId) + m.extract() + message.ack() + consumer.register_callback(handle_background_tasks_callback) + consumer.wait() # Go into the consumer loop. + diff --git a/oxdb/backend/management/commands/backgroundtasks.py b/oxdb/backend/management/commands/backgroundtasks.py index fb9731d8..7f48849a 100644 --- a/oxdb/backend/management/commands/backgroundtasks.py +++ b/oxdb/backend/management/commands/backgroundtasks.py @@ -1,20 +1,20 @@ # -*- coding: utf-8 -*- # vi:si:et:sw=4:sts=4:ts=4 -# j@v2v.cc + import os from os.path import join, dirname, basename, splitext, exists -from glob import glob from django.core.management.base import BaseCommand, CommandError from django.conf import settings from ... import daemon + class Command(BaseCommand): """ - listen to rabbitmq and execute background dasks. + listen to rabbitmq and execute background task. """ - help = 'listen to rabbitmq and execute background dasks.' + help = 'listen to rabbitmq and execute background task.' args = '' def handle(self, **options): diff --git a/oxdb/backend/models.py b/oxdb/backend/models.py index ffa17634..c9b99f77 100644 --- a/oxdb/backend/models.py +++ b/oxdb/backend/models.py @@ -1107,6 +1107,10 @@ class File(models.Model): self.movie = getMovie(info) self.save() + def extract(self): + #FIXME: do stuff, like create timeline or create smaller videos etc + return + class Still(models.Model): created = models.DateTimeField(auto_now_add=True) modified = models.DateTimeField(auto_now=True)