25 lines
No EOL
764 B
Python
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() |