+from datetime import timedelta
from django.core.management.base import BaseCommand
from django.db.models import F
+from django.utils.timezone import now
from sources.models import Source
class Command(BaseCommand):
def handle(self, **options):
- for s in Source.objects.exclude(
- modified_at=None
+ for s in Source.objects.filter(
+ modified_at__lt=now() - timedelta(seconds=60)
).exclude(processed_at__gt=F('modified_at')).order_by('modified_at'):
print(s)
try:
return os.path.isdir(d) and os.listdir(d)
def process(self):
+ processed_at = now()
updir = os.path.join(
settings.MEDIA_ROOT,
self.get_upload_directory()
self.build_view_directory(updir, d)
with utils.replace_dir(ocr_dir) as d:
self.build_ocr_directory(updir, d)
- self.processed_at = now()
+ self.processed_at = processed_at
self.save(update_fields=['processed_at'])
def build_view_directory(self, srcpath, targetpath):