Skip to main content

Crate bhtune_runtime

Crate bhtune_runtime 

Source
Expand description

Shared application runtime for BHTune’s command-line and HTTP adapters.

This crate owns configuration resolution, database bootstrap, logging, history retention, driver setup, tune orchestration and safety, shared OPC helpers, and sample export serialization. Its source and direct dependencies do not use clap or an HTTP framework; adapters convert their own inputs into runtime types and keep transport-specific output at the boundary. The OPC DA gRPC client may bring transport crates transitively, but they are not exposed through this runtime API.

Modules§

cancel
A single, process-wide Ctrl+C listener shared by every await point in a tune. Registering the signal exactly once, as early in the process as possible, closes the gap where a Ctrl+C delivered while no listener happens to be alive is silently swallowed – tokio installs a process-wide SIGINT handler the first time ctrl_c() is polled and never reverts to the OS default, so a lost signal isn’t merely unhandled, it’s gone.
config
Global bhtune configuration, including the shared [tuning] timing policy and the CLI flag > env var > TOML config file > built-in default precedence used by settings that expose command-line or environment overrides.
db
Opens the CLI’s database for mutating commands, seeds the built-in and user-catalog DCS/PLC templates, and runs the retention sweep. Read-only commands such as bhtune check use a separate connection that skips bootstrap and retention.
driver
Constructs the selected bhtune_driver::Driver implementation from a TuneRequest.
export
Shared serialization for persisted run samples.
gateway
Shared opcda-bridge compatibility checks for live mutations and inspection surfaces.
history
Shared history operations that can affect a live controller.
live_ownership
Process-shared and database-backed ownership for live controller mutations.
logging
Shared structured application logging, matching opcda-bridge-gateway’s own tracing stack and log.* configuration conventions (level/directory/format/rotation, resolved with the same CLI flag > env var > config file > default precedence as every other bhtune setting) – see crate::config::LogConfig/resolve_log_settings.
retention
Age-based deletion of old tune runs.
tune
bhtune tune/bhtune simulate: runs a full MRFT test end-to-end — resolving a template, deriving tags, transitioning the loop to Manual, polling the driver and driving a real [bhtune_core::MrftEngine], persisting every tick and the final calculated results, then restoring the loop and optionally writing back the chosen PID constants.