orangeqs.juice.settings._storing#
Module Contents#
Classes#
Base class for runtime data that can be stored to and loaded from disk. |
Data#
Path to the runtime directory for OrangeQS Juice, which is |
API#
- orangeqs.juice.settings._storing.SHARED_RUNTIME_PATH#
‘/var/run/juice’
Path to the runtime directory for OrangeQS Juice, which is
/var/run/juice.This is where shared runtime data is stored, such as service info and kernel specs. Even though this folder might contain sensitive data, for now this folder is shared with all OrangeQS Juice services and users.
- class orangeqs.juice.settings._storing.RuntimeData(/, **data: Any)#
Bases:
orangeqs.juice.settings._loading.ConfigurableBase class for runtime data that can be stored to and loaded from disk.
This base class should be subclassed by any model that needs to load/store its data from/to disk. The
filenameclass variable defines which files to load, which should be unique across all configurations and runtime data in OrangeQS Juice.Runtime data is stored at
SHARED_RUNTIME_PATH, which is shared between all OrangeQS Juice services and users.Examples#
Create a subclass of
RuntimeDatato store and load service information:from typing import ClassVar class ServiceInfo(RuntimeData): filename: ClassVar[str] = "service-info" state: dict[str, str] = Field(default_factory=dict) # From my-service service_info = ServiceInfo({ "my-service": "running", }) service_info.store(key="my-service") # From another service or process assert ServiceInfo.load()["my-service"] == "running"
- store(key: str, exist_ok: bool = False) pathlib.Path#
Store the runtime data to disk.
Will create a file in the shared runtime directory with the given key. It excludes fields that are not explicitly set or are None.
The runtime directory is defined by
SHARED_RUNTIME_PATH.Parameters#
key (str): The key of the runtime data file.
exist_ok (bool, optional): If True, do not raise an error if the file already exists. Defaults to False.
Returns#
(Path): The path to the stored file.
Raises#
(FileExistsError): If the file already exists and
exist_okis False.
See also
settings.SHARED_RUNTIME_PATH: Location where runtime data is stored.
- classmethod load(cache: bool = False) Self#
Load the runtime data from disk (default) or the cache.
This method loads the runtime data stored associated with this schema from the shared runtime directory.
The runtime directory is defined by
SHARED_RUNTIME_PATH.Parameters#
cache (bool, optional): If
True, return a cached instance if available; otherwise load from from disk and update the cache. IfFalse, always load from disk and update the cache. Defaults toFalse.
Returns#
(Self): An instance of the runtime data class loaded from disk (or the cache).