2020-05-24 15:44:27 +00:00
|
|
|
from celery import shared_task, task
|
|
|
|
from celery.utils.log import get_task_logger
|
|
|
|
|
|
|
|
logger = get_task_logger(__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)
|
2020-05-24 17:22:17 +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()
|
|
|
|
|