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
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())