27 lines
744 B
Python
27 lines
744 B
Python
|
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)
|
||
|
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()
|