expephalon/core/tasks/cron.py

30 lines
719 B
Python
Raw Normal View History

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