Refactor JobScheduler to use schedule.Job type and optimize healthcheck job scheduling logic

This commit is contained in:
Théophile Diot 2025-01-08 16:07:21 +01:00
parent 6222c0ad4a
commit 455abccb92
No known key found for this signature in database
GPG key ID: FA995104A0BA376A
2 changed files with 7 additions and 3 deletions

View file

@ -14,7 +14,6 @@ from pathlib import Path
import re
from typing import Any, Dict, List, Optional
import schedule
from schedule import Job
from sys import path as sys_path
from threading import Lock
@ -122,7 +121,7 @@ class JobScheduler(ApiCaller):
valid_jobs.append(job)
return valid_jobs
def __str_to_schedule(self, every: str) -> Job:
def __str_to_schedule(self, every: str) -> schedule.Job:
schedule_map = {
"minute": schedule.every().minute,
"hour": schedule.every().hour,

View file

@ -738,6 +738,7 @@ if __name__ == "__main__":
changed_plugins = []
old_changes = {}
healthcheck_job_run = False
while True:
threads.clear()
@ -753,6 +754,7 @@ if __name__ == "__main__":
LOGGER.info("All jobs in run_once() were successful")
if SCHEDULER.db.readonly:
generate_caches()
healthcheck_job_run = False
if CONFIG_NEED_GENERATION:
content = ""
@ -933,7 +935,10 @@ if __name__ == "__main__":
HEALTHY_PATH.write_text(datetime.now().astimezone().isoformat(), encoding="utf-8")
APPLYING_CHANGES.clear()
schedule_every(HEALTHCHECK_INTERVAL).seconds.do(healthcheck_job)
if not healthcheck_job_run:
LOGGER.debug("Scheduling healthcheck job ...")
schedule_every(HEALTHCHECK_INTERVAL).seconds.do(healthcheck_job)
healthcheck_job_run = True
# infinite schedule for the jobs
LOGGER.info("Executing job scheduler ...")