expephalon/core/tasks/cron.py
Klaus-Uwe Mitterer 95c9748dc2 Base logging setup
Models for products/services/billables
2020-05-27 12:36:49 +02:00

29 lines
719 B
Python

from celery import shared_task, task
import logging
logger = logging.getLogger(__name__)
@task(name="cron")
def process_crons():
from core.modules.cron import crondefinitions
for definition in crondefinitions:
if definition.is_due and not definition.is_running:
definition.run()
@shared_task
def run_cron(name, *args, **kwargs):
from core.models.cron import CronLog
from core.modules.cron import cronfunctions
log = CronLog.objects.create(task=name)
try:
output = cronfunctions[name]()
if output:
logger.debug(f"[{name}] {output}")
except Exception as e:
logger.error(f"[{name}] {str(e)}")
log.locked = False
log.save()