diff --git a/tasks.py b/tasks.py index a4647ec..066466c 100644 --- a/tasks.py +++ b/tasks.py @@ -4,26 +4,29 @@ from datetime import datetime from collections import Counter import ox -from celery.task import periodic_task from celery.schedules import crontab from django.db import transaction +from app.celery import app import itemlist.models import item.models import annotation.models import text.models -@periodic_task(run_every=crontab(hour=6, minute=0), queue='encoding') + +@app.task(queue='encoding') def cron(**kwargs): update_double_imdb() outofcopyright() update_keywords() + def outofcopyright(): for i in item.models.Item.objects.filter(sort__year__lt=datetime.now().year - 60, level=2): i.level = 1 i.save() + def update_double_imdb(): l = itemlist.models.List.get('j:Double IMDb') for i in item.models.Item.objects.filter(data__contains='imdbId').exclude(id__in=l.items.all()): @@ -37,6 +40,7 @@ def update_double_imdb(): transaction.commit() + def update_keywords(): t = text.models.Text.get('j:Keywords') keywords = Counter([a['value'] @@ -51,7 +55,8 @@ def update_keywords(): t.text = '\n'.join(data) t.save() -@periodic_task(run_every=crontab(minute=0), queue='encoding') + +@app.task(queue='encoding') def update_queued(): import archive.models l = itemlist.models.List.get('j:Queued') @@ -67,3 +72,10 @@ def update_queued(): if not i.files.filter(encoding=True).exists(): l.remove(i) transaction.commit() + + +@app.on_after_finalize.connect +def setup_periodic_tasks(sender, **kwargs): + sender.add_periodic_task(crontab(hour=6, minute=0), cron.s()) + sender.add_periodic_task(crontab(minute=0), update_queued.s()) +