corvix.web.runtime_config

Runtime AppConfig cache and dashboard selection helpers.

AppConfig is expensive to produce (YAML read + full parse). We cache the result at module level and invalidate it only when the config file’s mtime changes. A plain stat() per request is orders of magnitude cheaper than a full YAML re-parse, so we still detect on-disk edits without re-reading unconditionally on every HTTP request.

The three cache fields live in a single mutable object so they can be updated without global statements (which ruff PLW0603 flags).

Attributes

Classes

_ConfigCache

Mutable container for the module-level AppConfig cache.

Functions

_clear_config_cache(→ None)

Discard the cached AppConfig so the next request reloads from disk.

_load_runtime_config(→ corvix.config.AppConfig)

Return the cached AppConfig, re-parsing from disk only when the file changes.

_install_sighup_handler(→ None)

Register a SIGHUP handler that clears the config cache.

_select_dashboard(→ corvix.config.DashboardSpec)

_dashboard_names(→ list[str])

Module Contents

corvix.web.runtime_config.logger[source][source]
class corvix.web.runtime_config._ConfigCache[source][source]

Mutable container for the module-level AppConfig cache.

config: corvix.config.AppConfig | None = None[source][source]
path: str | None = None[source][source]
mtime: float | None = None[source][source]
corvix.web.runtime_config._config_cache[source][source]
corvix.web.runtime_config._clear_config_cache() None[source][source]

Discard the cached AppConfig so the next request reloads from disk.

corvix.web.runtime_config._load_runtime_config() corvix.config.AppConfig[source][source]

Return the cached AppConfig, re-parsing from disk only when the file changes.

Config is read from the path in the CORVIX_CONFIG environment variable (default: corvix.yaml). The file’s mtime is checked on every call; the YAML is only re-parsed when either the path or the mtime differs from the last successful load, eliminating redundant I/O on every request.

corvix.web.runtime_config._install_sighup_handler() None[source][source]

Register a SIGHUP handler that clears the config cache.

Sending SIGHUP to the server process forces the config to be reloaded from disk on the next request without restarting the process:

kill -HUP <pid>

The handler is a no-op on platforms that do not support SIGHUP (e.g. Windows).

corvix.web.runtime_config._select_dashboard(dashboards: list[corvix.config.DashboardSpec], selected_name: str | None) corvix.config.DashboardSpec[source][source]
corvix.web.runtime_config._dashboard_names(dashboards: list[corvix.config.DashboardSpec]) list[str][source][source]