add cronjob
This commit is contained in:
commit
079d2b5ad7
4 changed files with 32 additions and 0 deletions
0
__init__.py
Normal file
0
__init__.py
Normal file
3
models.py
Normal file
3
models.py
Normal file
|
@ -0,0 +1,3 @@
|
|||
from django.db import models
|
||||
|
||||
# Create your models here.
|
28
tasks.py
Normal file
28
tasks.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# vi:si:et:sw=4:sts=4:ts=4
|
||||
|
||||
from celery.task import periodic_task
|
||||
from celery.schedules import crontab
|
||||
from django.db import transaction
|
||||
|
||||
import itemlist.models
|
||||
import item.models
|
||||
|
||||
@periodic_task(run_every=crontab(hour=6, minute=0), queue='encoding')
|
||||
def cron(**kwargs):
|
||||
update_double_imdb()
|
||||
|
||||
|
||||
def update_double_imdb():
|
||||
l = itemlist.models.List.get(name='Double IMDb', user__username='j')
|
||||
for i in item.models.Item.objects.filter(data__contains='imdbId').exclude(id__in=l.items.all()):
|
||||
if item.models.Item.objects.exclude(id=i.id).filter(sort__imdbId=i.sort.imdbId).exists():
|
||||
l.add(i)
|
||||
|
||||
for i in l.items.all():
|
||||
if not i.get('imdbId') or \
|
||||
item.models.Item.objects.filter(sort__imdbId=i.sort.imdbId).count() == 1:
|
||||
l.remove(i)
|
||||
|
||||
transaction.commit_unless_managed()
|
||||
|
1
views.py
Normal file
1
views.py
Normal file
|
@ -0,0 +1 @@
|
|||
# Create your views here.
|
Loading…
Reference in a new issue