Skip to main content

DfeApp

Trait DfeApp 

Source
pub trait DfeApp: Sized {
    type Config: DeserializeOwned + Debug + Send + Sync;

    // Required methods
    fn name(&self) -> &str;
    fn env_prefix(&self) -> &str;
    fn version_info(&self) -> VersionInfo;
    fn common_args(&self) -> &CommonArgs;
    fn load_config(&self, path: Option<&str>) -> Result<Self::Config, CliError>;
    fn run_service(
        &self,
        config: Self::Config,
        runtime: ServiceRuntime,
    ) -> impl Future<Output = Result<(), CliError>> + Send;

    // Provided methods
    fn command(&self) -> Option<&StandardCommand> { ... }
    fn scaling_components(
        &self,
        _config: &Self::Config,
    ) -> Vec<ScalingComponent> { ... }
    fn register_metrics(&self, _manager: &MetricsManager) { ... }
    fn deployment_contract(&self) -> Option<DeploymentContract> { ... }
}
Available on crate feature cli only.
Expand description

Trait for DFE service applications.

Implement this trait to get the standard CLI lifecycle for free. The 80% common behaviour (logging, config, metrics, version) is handled by run_app(). Your app provides the 20% (config type, service logic).

Required Associated Types§

Source

type Config: DeserializeOwned + Debug + Send + Sync

Application-specific configuration type.

Required Methods§

Source

fn name(&self) -> &str

Service name (e.g. “dfe-loader”).

Source

fn env_prefix(&self) -> &str

Environment variable prefix for config cascade (e.g. “DFE_LOADER”).

Source

fn version_info(&self) -> VersionInfo

Version information for this service.

Source

fn common_args(&self) -> &CommonArgs

Access the common CLI arguments.

Source

fn load_config(&self, path: Option<&str>) -> Result<Self::Config, CliError>

Load application configuration from the given path (or defaults).

§Errors

Returns CliError if configuration cannot be loaded or parsed.

Source

fn run_service( &self, config: Self::Config, runtime: ServiceRuntime, ) -> impl Future<Output = Result<(), CliError>> + Send

Run the main service loop.

Called after logging, config, and ServiceRuntime are initialised. The runtime contains all common infrastructure (metrics, memory guard, shutdown token, worker pool, scaling pressure). Apps just use it – no boilerplate needed.

§Errors

Returns CliError if the service encounters a fatal error.

Provided Methods§

Source

fn command(&self) -> Option<&StandardCommand>

Resolve the active subcommand.

Returns None to default to StandardCommand::Run.

Source

fn scaling_components(&self, _config: &Self::Config) -> Vec<ScalingComponent>

Available on crate feature scaling only.

Provide scaling pressure components for KEDA autoscaling.

Override to register app-specific scaling signals (buffer depth, consumer lag, error rate, etc.). The default returns an empty vec.

Source

fn register_metrics(&self, _manager: &MetricsManager)

Available on crate features metrics or otel-metrics only.

Register all metrics for this service.

Called by metrics-manifest and generate-artefacts subcommands to capture the full metric catalogue without starting the service. The default implementation is a no-op. Override to register DfeMetrics, metric groups, and app-specific metrics.

Source

fn deployment_contract(&self) -> Option<DeploymentContract>

Available on crate feature deployment only.

Build the deployment contract for this service.

Called by generate-artefacts to produce container specs, health endpoints, KEDA config, and metrics manifest. The default returns None. Override to provide a contract.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§