Skip to content

Commit

Permalink
temporary
Browse files Browse the repository at this point in the history
  • Loading branch information
amadolid committed Sep 8, 2023
1 parent 8e00e3a commit 7bcc16f
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 11 deletions.
16 changes: 7 additions & 9 deletions jaseci_core/jaseci/extens/api/jsorc_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,14 @@ def service_info(self, name: str):
"""

# will throw exception if not existing
svc = JsOrc.svc(name)
return JsOrc.svc(name).info()

return {
"enabled": svc.enabled,
"automated": svc.automated,
"quiet": svc.quiet,
"state": svc.state.name,
"config": svc.config,
"error": str(svc.error) if svc.error else None,
}
@Interface.admin_api(cli_args=["name"])
def service_config_set(self, name: str, config: dict):
"""
Set a service config
"""
return JsOrc.svc_conf_set(name, config, self._h).info()

@Interface.admin_api(cli_args=["name"])
def service_refresh(self, name: str):
Expand Down
28 changes: 26 additions & 2 deletions jaseci_core/jaseci/jsorc/jsorc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from time import sleep
from copy import deepcopy
from json import dumps
from json import dumps, loads
from datetime import datetime
from typing import TypeVar, Any, Union

Expand Down Expand Up @@ -50,6 +50,7 @@ class JsOrc:
_config = None
_backoff_interval = 10
_running_interval = 0
_multi_node = True
__running__ = False
__proxy__ = cs.proxy()

Expand Down Expand Up @@ -80,6 +81,7 @@ def configure(cls):
cls._config = config
cls._backoff_interval = max(5, config.get("backoff_interval", 10))
cls._regeneration_queues = config.get("pre_loaded_services", [])
cls._multi_node = config.get("multi_node", True)

@classmethod
def run(cls):
Expand Down Expand Up @@ -261,9 +263,31 @@ def svc(cls, service: str, cast: T = None) -> Union[T, cs]:
if cls._use_proxy and cls._services[service][0]["proxy"]:
return cls.__proxy__
cls._service_instances[service] = cls._svc(service)
elif cls._multi_node and not cls._use_proxy:
svc = cls._service_instances[service]
config: dict = loads(
cls.hook(use_proxy=svc.source["proxy"]).get_glob(svc.source["config"])
)
if svc.version != config.get("__version__"):
return cls.svc_reset(service)

return cls._service_instances[service]

@classmethod
def svc_conf_set(
cls, service: str, config: dict, hook: None, cast: T = None
) -> Union[T, cs]:
if service not in cls._services:
raise Exception(f"Service {service} is not existing!")

if cls.db_check():
instance = cls._services[service][0]
hook = hook or cls.hook(use_proxy=instance["proxy"])
config["__version__"] = int(datetime.utcnow().timestamp())
hook.save_glob(instance["config"], dumps(config))

return cls.svc_reset(service)

@classmethod
def svc_reset(cls, service, cast: T = None) -> Union[T, cs]:
"""
Expand Down Expand Up @@ -333,7 +357,7 @@ def decorator(service: T) -> T:
target=cls._services,
entry={
"type": service,
"config": config or f"{name.upper()}_CONFIG",
"config": (config or f"{name}_CONFIG").upper(),
"manifest": manifest,
"manifest_type": manifest_type,
"priority": priority,
Expand Down
14 changes: 14 additions & 0 deletions jaseci_core/jaseci/jsorc/jsorc_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ def __init__(
self.enabled = config.pop("enabled", False)
self.quiet = config.pop("quiet", False)
self.automated = config.pop("automated", False)
self.version = config.pop("__version__", 0)

# ------------------ MANIFEST ------------------- #

Expand Down Expand Up @@ -284,3 +285,16 @@ def __setstate__(self, ignored):
# for build on pickle load
self.state = State.FAILED
del self

# ------------------- COMMON -------------------- #

def info(self):
return {
"enabled": self.enabled,
"automated": self.automated,
"version": self.version,
"quiet": self.quiet,
"state": self.state.name,
"config": self.config,
"error": str(self.error) if self.error else None,
}

0 comments on commit 7bcc16f

Please sign in to comment.