mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Refactor JobScheduler to use schedule.Job type and optimize healthcheck job scheduling logic
This commit is contained in:
parent
6222c0ad4a
commit
455abccb92
2 changed files with 7 additions and 3 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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 ...")
|
||||
|
|
|
|||
Loading…
Reference in a new issue