runtime_config.py
Overview
runtime_config.py defines the RuntimeConfig class, which serves as a centralized, runtime-configurable container for global application settings in the InfiniFlow system. It provides mechanisms to initialize, update, and retrieve various configuration parameters and environment information dynamically during the execution of the application.
This file primarily focuses on managing runtime configuration values such as debug mode, operational mode, HTTP port, job server details, environment metadata, and database service references. It inherits from a base reloading configuration class (ReloadConfigBase), indicating it may support live configuration reloads or updates.
Classes and Methods
Class: RuntimeConfig
RuntimeConfig is a singleton-style class with only class-level attributes and methods. It is not designed for instance creation but serves as a global state holder for runtime configuration.
Attributes (Class Variables)
Attribute | Type | Description |
|---|---|---|
|
| Indicates if debug mode is enabled. Defaults to |
|
| Represents the current work mode of the application. |
|
| The HTTP server port number the service listens on. |
|
| Hostname or IP for the job server. |
|
| Virtual IP for the job server (used for failover/load balancing). |
|
| Dictionary holding environment metadata (e.g., version). |
| Any | Reference to the service database connection or manager. |
|
| Flag indicating whether the configuration manager should be loaded. Defaults to |
Methods
All methods are class methods, meaning they operate on the class state rather than instance state.
init_config(cls, **kwargs)
Initializes or updates configuration attributes of the class based on provided keyword arguments.
Parameters:
**kwargs: Arbitrary keyword arguments where keys correspond to attribute names inRuntimeConfigand values are the values to set.
Returns:
NoneUsage Example:
RuntimeConfig.init_config(DEBUG=True, HTTP_PORT=8080, WORK_MODE="production")
This will set the DEBUG flag to True, the HTTP port to 8080, and the work mode to "production".
Details:
Only updates attributes that already exist in the class.
Ignores unknown keys silently.
init_env(cls)
Initializes environment metadata by updating the ENV dictionary with the current ragflow version fetched from the external module.
Parameters: None
Returns:
NoneUsage Example:
RuntimeConfig.init_env()
print(RuntimeConfig.get_env("version")) # Outputs current ragflow version
Details:
Calls
get_ragflow_version()imported fromapi.versionsto retrieve the version string.Updates the
ENVdictionary with a"version"key.
load_config_manager(cls)
Sets the LOAD_CONFIG_MANAGER flag to True to indicate that the configuration manager should be loaded.
Parameters: None
Returns:
NoneUsage Example:
RuntimeConfig.load_config_manager()
Details:
This flag can be checked elsewhere in the system to trigger dynamic configuration manager loading.
get_env(cls, key)
Retrieves the value of an environment variable stored inside the ENV dictionary by key.
Parameters:
key(str): The key/name of the environment variable to retrieve.
Returns: The value associated with the key, or
Noneif the key is not found.Usage Example:
version = RuntimeConfig.get_env("version")
print(version)
get_all_env(cls)
Returns the entire environment dictionary.
Parameters: None
Returns:
dictcontaining all environment variables.Usage Example:
all_env = RuntimeConfig.get_all_env()
print(all_env)
set_service_db(cls, service_db)
Sets the SERVICE_DB attribute to the provided service database object.
Parameters:
service_db(Any): An object representing the service database connection or manager.
Returns:
NoneUsage Example:
RuntimeConfig.set_service_db(my_service_db_instance)
Details:
This enables other parts of the system to access the database service via
RuntimeConfig.
Important Implementation Details
Class-Level State:
The class uses class variables exclusively, making it a singleton-like global configuration holder accessible throughout the application without needing to instantiate objects.Dynamic Initialization:
Theinit_configmethod allows flexible runtime configuration by accepting arbitrary keyword arguments and updating known attributes only.Version Management:
Theinit_envmethod integrates with the externalapi.versionsmodule to keep track of the current software version dynamically, which is useful for debugging, logging, and environment tracking.Configuration Manager Flag:
TheLOAD_CONFIG_MANAGERboolean flag suggests an architectural pattern where runtime configuration can trigger a dynamic loading or reloading of configuration managers, supporting possibly hot-reloadable configurations or modular config management.Loose Coupling:
TheSERVICE_DBattribute is generic, allowing any database service object to be attached at runtime, promoting flexibility in database implementations.
Interaction with Other System Components
ReloadConfigBaseBase Class:RuntimeConfiginherits fromReloadConfigBase, which likely provides foundational functionality for reloading or refreshing configurations dynamically. This indicates thatRuntimeConfigis part of a broader configuration management framework.api.versions.get_ragflow_version:
The version retrieval function is imported from another module, tying runtime environment metadata into the broader InfiniFlow versioning system.Service Database (
SERVICE_DB):
The class holds a reference to the service database instance, which is presumably used by various system components for data persistence and retrieval.Configuration Manager Loading:
TheLOAD_CONFIG_MANAGERflag suggests coordination with a configuration manager component elsewhere in the system that monitors this flag to initiate loading or reloading configuration data.
Usage Summary
RuntimeConfig is designed to be imported and used throughout the InfiniFlow application wherever runtime configuration or environment information is needed. It allows centralized updates and lookups for critical configuration parameters and environment metadata.
Class Structure Diagram
classDiagram
class RuntimeConfig {
<<singleton>>
+DEBUG: bool
+WORK_MODE: str
+HTTP_PORT: int
+JOB_SERVER_HOST: str
+JOB_SERVER_VIP: str
+ENV: dict
+SERVICE_DB: Any
+LOAD_CONFIG_MANAGER: bool
+init_config(kwargs)
+init_env()
+load_config_manager()
+get_env(key)
+get_all_env()
+set_service_db(service_db)
}
RuntimeConfig --|> ReloadConfigBase
Summary
The runtime_config.py file is a critical utility for managing runtime settings and environment metadata within InfiniFlow. Its design promotes easy, centralized, and dynamic configuration updates, integration with system versioning, and flexible service database assignment, all while supporting potential runtime configuration reloads. This design pattern helps maintain system consistency and flexibility in a distributed or modular application environment.