mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Refactor JobScheduler to improve environment handling by ensuring job modules receive a copy of the environment and updating the environment consistently across job execution.
This commit is contained in:
parent
b5079b7fac
commit
49084d6561
1 changed files with 9 additions and 2 deletions
|
|
@ -41,7 +41,7 @@ class JobScheduler(ApiCaller):
|
|||
super().__init__(apis or [])
|
||||
self.__logger = logger or setup_logger("Scheduler", getenv("CUSTOM_LOG_LEVEL", getenv("LOG_LEVEL", "INFO")))
|
||||
self.db = db or Database(self.__logger)
|
||||
self.__env = {**environ, **(env or {})}
|
||||
self.__env = environ | env
|
||||
self.__lock = lock
|
||||
self.__thread_lock = Lock()
|
||||
self.__job_success = True
|
||||
|
|
@ -166,7 +166,8 @@ class JobScheduler(ApiCaller):
|
|||
start_date = datetime.now().astimezone()
|
||||
try:
|
||||
module = self.__load_plugin_module(join(path, "jobs", file), name)
|
||||
ret = module.run(self.__env)
|
||||
job_env = self.__env.copy()
|
||||
ret = module.run(job_env)
|
||||
except SystemExit as e:
|
||||
ret = e.code
|
||||
except Exception as e:
|
||||
|
|
@ -245,6 +246,8 @@ class JobScheduler(ApiCaller):
|
|||
self.__job_success = True
|
||||
self.__job_reload = False
|
||||
|
||||
environ.update(environ | self.__env)
|
||||
|
||||
# Use ThreadPoolExecutor to run jobs
|
||||
futures = [self.__executor.submit(job.run) for job in pending_jobs]
|
||||
|
||||
|
|
@ -290,6 +293,8 @@ class JobScheduler(ApiCaller):
|
|||
|
||||
plugins = plugins or []
|
||||
|
||||
environ.update(environ | self.__env)
|
||||
|
||||
futures = []
|
||||
for plugin, jobs in self.__jobs.items():
|
||||
jobs_to_run = []
|
||||
|
|
@ -344,6 +349,8 @@ class JobScheduler(ApiCaller):
|
|||
self.__lock.release()
|
||||
return False
|
||||
|
||||
environ.update(environ | self.__env)
|
||||
|
||||
self.__job_wrapper(
|
||||
job_to_run["path"],
|
||||
job_plugin,
|
||||
|
|
|
|||
Loading…
Reference in a new issue