"""
runtime holder
"""
import importlib
from yr import _preload_native_libraries
_preload_native_libraries()
class RuntimeHolder:
"""
runtime holder
"""
def __init__(self):
self.yr_runtime = None
def init(self, runtime):
"""init"""
self.yr_runtime = runtime
def get_runtime(self):
"""get runtime"""
runtime = self.yr_runtime
if runtime is None:
raise RuntimeError("runtime not enable, please call yr.init() first")
return runtime
global_runtime = RuntimeHolder()
def save_real_instance_id(instance_id, need_order):
"""
save real instance id
:param instance_id: instance id
:param need_order: need order
:return: None
"""
global_runtime.get_runtime().save_real_instance_id(instance_id, need_order)
def init(runtime=global_runtime) -> None:
"""
init yr
:param runtime: RuntimeHolder
:return: None
"""
config_manager_cls = importlib.import_module("yr.config_manager").ConfigManager
if config_manager_cls().local_mode:
local_mode_runtime_cls = importlib.import_module(
"yr.local_mode.local_mode_runtime"
).LocalModeRuntime
rt = local_mode_runtime_cls()
rt.init()
else:
cluster_mode_runtime_cls = importlib.import_module(
"yr.cluster_mode_runtime"
).ClusterModeRuntime
rt = cluster_mode_runtime_cls()
rt.init()
runtime.init(rt)