Files
crank/crates/crank-runtime/src/executor_builder.rs
T
bsodfather 8318e4b560
CI / Rust Checks (push) Successful in 5m7s
CI / UI Checks (push) Successful in 4s
CI / Deployment Manifests (push) Successful in 3s
CI / Frontend E2E (push) Successful in 3m9s
CI / Deploy (push) Successful in 1m41s
Усилить безопасность и надёжность выполнения операций
2026-07-11 14:08:07 +03:00

86 lines
2.5 KiB
Rust

use std::sync::Arc;
use crank_adapter_rest::{OutboundHttpPolicy, RestAdapter, RestAdapterError};
use crank_core::{
AdapterRegistry, CoordinationStateStore, MeteringSink, NoopMeteringSink, ResponseCacheStore,
SharedMeteringSink, SharedProtocolAdapter,
};
use crate::{RuntimeExecutor, RuntimeLimits};
pub struct RuntimeExecutorBuilder {
limits: RuntimeLimits,
adapters: AdapterRegistry,
response_cache: Option<Arc<dyn ResponseCacheStore>>,
coordination_store: Option<Arc<dyn CoordinationStateStore>>,
metering_sink: SharedMeteringSink,
}
impl RuntimeExecutorBuilder {
pub fn new() -> Self {
Self {
limits: RuntimeLimits::default(),
adapters: AdapterRegistry::empty(),
response_cache: None,
coordination_store: None,
metering_sink: Arc::new(NoopMeteringSink) as Arc<dyn MeteringSink>,
}
}
pub fn with_limits(mut self, limits: RuntimeLimits) -> Self {
self.limits = limits;
self
}
pub fn register_adapter(mut self, adapter: SharedProtocolAdapter) -> Self {
self.adapters = self.adapters.register(adapter);
self
}
pub fn with_response_cache(mut self, store: Arc<dyn ResponseCacheStore>) -> Self {
self.response_cache = Some(store);
self
}
pub fn with_coordination_store(mut self, store: Arc<dyn CoordinationStateStore>) -> Self {
self.coordination_store = Some(store);
self
}
pub fn with_metering_sink(mut self, sink: SharedMeteringSink) -> Self {
self.metering_sink = sink;
self
}
pub fn build(self) -> RuntimeExecutor {
RuntimeExecutor::from_builder_parts(
self.limits,
self.adapters,
self.response_cache,
self.coordination_store,
self.metering_sink,
)
}
}
impl Default for RuntimeExecutorBuilder {
fn default() -> Self {
Self::new()
}
}
pub fn community_default() -> RuntimeExecutorBuilder {
RuntimeExecutorBuilder::new()
.register_adapter(Arc::new(RestAdapter::new()) as SharedProtocolAdapter)
}
pub fn community_from_env() -> Result<RuntimeExecutorBuilder, RestAdapterError> {
Ok(RuntimeExecutorBuilder::new()
.register_adapter(Arc::new(RestAdapter::from_env()?) as SharedProtocolAdapter))
}
pub fn community_with_outbound_policy(policy: OutboundHttpPolicy) -> RuntimeExecutorBuilder {
RuntimeExecutorBuilder::new()
.register_adapter(Arc::new(RestAdapter::with_policy(policy)) as SharedProtocolAdapter)
}