-from os.path import join, abspath, exists
-from django.db import models
-from waiter.settings import WAITER_ROOT, WAITER_URL
+# -*- coding: utf-8 -*-
+# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
+#
+from os.path import join, isfile
+from django.db import models
+from waiter.settings import WAITER_URL, WAITER_MAX_QUEUE
+from waiter.utils import check_abspath
+from picklefield import PickledObjectField
+
class WaitedFile(models.Model):
path = models.CharField(max_length=255, unique=True, db_index=True)
class WaitedFile(models.Model):
path = models.CharField(max_length=255, unique=True, db_index=True)
- task = models.CharField(max_length=64, null=True, editable=False)
+ task_id = models.CharField(max_length=128, db_index=True, null=True, blank=True)
+ task = PickledObjectField(null=True, editable=False)
@classmethod
def order(cls, path, task_creator, description=None):
"""
Returns an URL for the user to follow.
If the file is ready, returns download URL.
If not, starts preparing it and returns waiting URL.
@classmethod
def order(cls, path, task_creator, description=None):
"""
Returns an URL for the user to follow.
If the file is ready, returns download URL.
If not, starts preparing it and returns waiting URL.
"""
already = cls.exists(path)
if not already:
waited, created = cls.objects.get_or_create(path=path)
"""
already = cls.exists(path)
if not already:
waited, created = cls.objects.get_or_create(path=path)
- if created:
- # TODO: makedirs
- waited.task = task_creator(cls.abspath(path))
- print waited.task
+ if created or waited.is_stale():
+ waited.task = task_creator(check_abspath(path), waited.pk)
+ waited.task_id = waited.task.task_id
return reverse("waiter", args=[path])
return join(WAITER_URL, path)
return reverse("waiter", args=[path])
return join(WAITER_URL, path)