add task functions to File

This commit is contained in:
j 2013-11-10 18:30:34 +00:00
parent 3f4b1b3d63
commit 7dde9eb8ae
2 changed files with 10 additions and 4 deletions

View file

@ -20,7 +20,6 @@ from person.models import get_name_sort
import extract
class File(models.Model):
AV_INFO = (
'duration', 'video', 'audio', 'oshash', 'size',
@ -139,7 +138,6 @@ class File(models.Model):
if self.framerate:
self.pixels = int(self.width * self.height * float(utils.parse_decimal(self.framerate)) * self.duration)
def get_path_info(self):
data = {}
for key in self.PATH_INFO:
@ -389,6 +387,14 @@ class File(models.Model):
def all_paths(self):
return [self.path] + [i.path for i in self.instances.all()]
def extract_stream(self):
import tasks
return tasks.extract_stream.delay(self.id)
def process_stream(self):
import tasks
return tasks.process_stream.delay(self.id)
def delete(self, *args, **kwargs):
self.delete_files()
super(File, self).delete(*args, **kwargs)

View file

@ -247,7 +247,7 @@ def firefogg_upload(request):
f.save()
#FIXME: this fails badly if rabbitmq goes down
try:
t = tasks.process_stream.delay(f.id)
t = f.process_stream()
response['resultUrl'] = t.task_id
except:
pass
@ -300,7 +300,7 @@ def direct_upload(request):
file.save()
#try/execpt so it does not fail if rabitmq is down
try:
t = tasks.extract_stream.delay(file.id)
t = file.extract_stream()
response['resultUrl'] = t.task_id
except:
pass