From b8215d27366612a63cce2555c4a575380264f52d Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Thu, 27 Oct 2022 10:44:23 +0200 Subject: [PATCH] A more robust cron start logic If may happen (usually because of a race condition) that a cronjob has already been started, but it hasn't yet changed its status from IDLE to RUNNING when the scheduler checks it. This fix guards the application against such events. If they occur, we should just report them and move on, not terminate the whole scheduler. --- platypush/cron/scheduler.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/platypush/cron/scheduler.py b/platypush/cron/scheduler.py index 86fbff62a..18f1ee8bd 100644 --- a/platypush/cron/scheduler.py +++ b/platypush/cron/scheduler.py @@ -153,7 +153,10 @@ class CronScheduler(threading.Thread): for (job_name, job_config) in self.jobs_config.items(): job = self._get_job(name=job_name, config=job_config) if job.state == CronjobState.IDLE: - job.start() + try: + job.start() + except Exception as e: + logger.warning(f'Could not start cronjob {job_name}: {e}') t_before_wait = get_now().timestamp() self._should_stop.wait(timeout=self._poll_seconds)