2020-05-24 15:44:27 +00:00
|
|
|
from celery import shared_task, task
|
|
|
|
|
2020-05-27 10:36:49 +00:00
|
|
|
import logging
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
2020-05-24 15:44:27 +00:00
|
|
|
|
|
|
|
@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)
|
2020-05-27 10:36:49 +00:00
|
|
|
|
2020-05-24 15:44:27 +00:00
|
|
|
try:
|
|
|
|
output = cronfunctions[name]()
|
|
|
|
if output:
|
|
|
|
logger.debug(f"[{name}] {output}")
|
|
|
|
except Exception as e:
|
|
|
|
logger.error(f"[{name}] {str(e)}")
|
|
|
|
log.locked = False
|
2020-05-24 17:22:17 +00:00
|
|
|
log.save()
|
|
|
|
|