update periodic tasks

This commit is contained in:
j 2023-08-25 00:07:52 +02:00
parent 4fed9cbe58
commit c0c76f2ed5

View file

@ -4,26 +4,29 @@ from datetime import datetime
from collections import Counter from collections import Counter
import ox import ox
from celery.task import periodic_task
from celery.schedules import crontab from celery.schedules import crontab
from django.db import transaction from django.db import transaction
from app.celery import app
import itemlist.models import itemlist.models
import item.models import item.models
import annotation.models import annotation.models
import text.models import text.models
@periodic_task(run_every=crontab(hour=6, minute=0), queue='encoding')
@app.task(queue='encoding')
def cron(**kwargs): def cron(**kwargs):
update_double_imdb() update_double_imdb()
outofcopyright() outofcopyright()
update_keywords() update_keywords()
def outofcopyright(): def outofcopyright():
for i in item.models.Item.objects.filter(sort__year__lt=datetime.now().year - 60, level=2): for i in item.models.Item.objects.filter(sort__year__lt=datetime.now().year - 60, level=2):
i.level = 1 i.level = 1
i.save() i.save()
def update_double_imdb(): def update_double_imdb():
l = itemlist.models.List.get('j: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()): 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() transaction.commit()
def update_keywords(): def update_keywords():
t = text.models.Text.get('j:Keywords') t = text.models.Text.get('j:Keywords')
keywords = Counter([a['value'] keywords = Counter([a['value']
@ -51,7 +55,8 @@ def update_keywords():
t.text = '\n'.join(data) t.text = '\n'.join(data)
t.save() t.save()
@periodic_task(run_every=crontab(minute=0), queue='encoding')
@app.task(queue='encoding')
def update_queued(): def update_queued():
import archive.models import archive.models
l = itemlist.models.List.get('j:Queued') l = itemlist.models.List.get('j:Queued')
@ -67,3 +72,10 @@ def update_queued():
if not i.files.filter(encoding=True).exists(): if not i.files.filter(encoding=True).exists():
l.remove(i) l.remove(i)
transaction.commit() 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())