mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Improve dynamic module import in JobScheduler to manage sys.path more safely
This commit is contained in:
parent
08cba813c6
commit
b27ed6f94d
1 changed files with 8 additions and 3 deletions
|
|
@ -155,9 +155,14 @@ class JobScheduler(ApiCaller):
|
|||
|
||||
def __exec_plugin_module(self, path: str, name: str) -> ModuleType:
|
||||
"""Dynamically import plugin module."""
|
||||
spec = spec_from_file_location(name, path)
|
||||
module = module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
module_dir = dirname(path)
|
||||
sys_path.insert(0, module_dir)
|
||||
try:
|
||||
spec = spec_from_file_location(name, path)
|
||||
module = module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
finally:
|
||||
sys_path.remove(module_dir)
|
||||
|
||||
def __job_wrapper(self, path: str, plugin: str, name: str, file: str) -> int:
|
||||
self.__logger.info(f"Executing job '{name}' from plugin '{plugin}'...")
|
||||
|
|
|
|||
Loading…
Reference in a new issue