From 42d519535bd4445ef0fa8279876bc6eb9560ad6b Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Fri, 5 Aug 2011 16:00:25 +0200 Subject: [PATCH] concurrency: no save in tasks --- apps/archive/tasks.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/apps/archive/tasks.py b/apps/archive/tasks.py index 9af3492..e257da0 100755 --- a/apps/archive/tasks.py +++ b/apps/archive/tasks.py @@ -31,8 +31,8 @@ class AudioFormatTask(Task): @classmethod def set_status(cls, audiobook, status): - setattr(audiobook, '%s_status' % cls.ext, status) - audiobook.save() + Audiobook.objects.filter(pk=audiobook.pk).update( + **{'%s_status' % cls.ext: status}) @staticmethod def encode(in_path, out_path): @@ -54,11 +54,14 @@ class AudioFormatTask(Task): @classmethod def published(cls, audiobook): - setattr(audiobook, "%s_published_tags" % cls.ext, - getattr(audiobook, "%s_tags" % cls.ext)) - setattr(audiobook, "%s_tags" % cls.ext, None) - setattr(audiobook, "%s_published" % cls.ext, datetime.now()) - cls.set_status(audiobook, None) + kwargs = { + "%s_published_tags" % cls.ext: + getattr(audiobook, "%s_tags" % cls.ext), + "%s_tags" % cls.ext: None, + "%s_published" % cls.ext: datetime.now(), + '%s_status' % cls.ext: None, + } + Audiobook.objects.filter(pk=audiobook.pk).update(**kwargs) @classmethod def put(cls, audiobook): @@ -72,7 +75,6 @@ class AudioFormatTask(Task): pipes.quote(slug), pipes.quote(name) )).encode('utf-8') - print command if UPLOAD_SUDO: api.sudo(command, user=UPLOAD_SUDO, shell=False) else: @@ -101,7 +103,6 @@ class AudioFormatTask(Task): self.put(audiobook) self.published(audiobook) - audiobook.save() class Mp3Task(AudioFormatTask): -- 2.20.1