expephalon/core/helpers/cron.py
Klaus-Uwe Mitterer 2e8bbdd8a7 A lot of new views
Color picker fields
Renamed pixel.png in order not to upset uBlock...
2020-06-02 17:58:20 +02:00

25 lines
No EOL
764 B
Python

from django_celery_beat.models import PeriodicTask, IntervalSchedule
from django_celery_results.models import TaskResult
from django.utils import timezone
from dbsettings.functions import getValue
def setup_cron(frequency=int(getValue("core.cron.frequency", 5))):
schedule, created = IntervalSchedule.objects.get_or_create(
every=frequency,
period=IntervalSchedule.SECONDS,
)
cron = PeriodicTask.objects.get_or_create(
name='Expephacron',
task='cron',
)[0]
cron.interval = schedule
cron.save()
def clear_cron_log(maxage=int(getValue("core.cron.log.retention", 86400))):
timestamp = timezone.now() - timezone.timedelta(seconds=maxage)
TaskResult.objects.filter(date_done__lt=timestamp).delete()