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

DEBUG

bool or None

Indicates if debug mode is enabled. Defaults to None.

WORK_MODE

str or None

Represents the current work mode of the application.

HTTP_PORT

int or None

The HTTP server port number the service listens on.

JOB_SERVER_HOST

str or None

Hostname or IP for the job server.

JOB_SERVER_VIP

str or None

Virtual IP for the job server (used for failover/load balancing).

ENV

dict

Dictionary holding environment metadata (e.g., version).

SERVICE_DB

Any

Reference to the service database connection or manager.

LOAD_CONFIG_MANAGER

bool

Flag indicating whether the configuration manager should be loaded. Defaults to False.


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.

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".


init_env(cls)

Initializes environment metadata by updating the ENV dictionary with the current ragflow version fetched from the external module.

RuntimeConfig.init_env()
print(RuntimeConfig.get_env("version"))  # Outputs current ragflow version

load_config_manager(cls)

Sets the LOAD_CONFIG_MANAGER flag to True to indicate that the configuration manager should be loaded.

RuntimeConfig.load_config_manager()

get_env(cls, key)

Retrieves the value of an environment variable stored inside the ENV dictionary by key.

version = RuntimeConfig.get_env("version")
print(version)

get_all_env(cls)

Returns the entire environment dictionary.

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.

RuntimeConfig.set_service_db(my_service_db_instance)

Important Implementation Details


Interaction with Other System Components


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.