runtime: add executor builder
This commit is contained in:
@@ -152,5 +152,6 @@ Progress:
|
|||||||
- Phase 0 / task `0.8`: введены `ProtocolAdapter`, `ProtocolAdapterError`, `AdapterRegistry` и базовые transport-типы (`PreparedRequest`, `AdapterResponse`, `WindowExecutionResult`, `RuntimeRequestContext`) в `crank_core::ext::protocol`
|
- Phase 0 / task `0.8`: введены `ProtocolAdapter`, `ProtocolAdapterError`, `AdapterRegistry` и базовые transport-типы (`PreparedRequest`, `AdapterResponse`, `WindowExecutionResult`, `RuntimeRequestContext`) в `crank_core::ext::protocol`
|
||||||
- Phase 0 / task `0.9`: `crank-adapter-rest::RestAdapter` реализует новый `ProtocolAdapter` contract, а seam дополнен явным `Target` и window parameters для реального adapter wiring
|
- Phase 0 / task `0.9`: `crank-adapter-rest::RestAdapter` реализует новый `ProtocolAdapter` contract, а seam дополнен явным `Target` и window parameters для реального adapter wiring
|
||||||
- Phase 0 / task `0.10`: `RuntimeExecutor` переведен с hardcoded adapter fields на `AdapterRegistry`, `crank-runtime` больше не держит protocol feature flags, а общий `PreparedRequest` seam дополнен `timeout_ms` для корректного runtime dispatch
|
- Phase 0 / task `0.10`: `RuntimeExecutor` переведен с hardcoded adapter fields на `AdapterRegistry`, `crank-runtime` больше не держит protocol feature flags, а общий `PreparedRequest` seam дополнен `timeout_ms` для корректного runtime dispatch
|
||||||
|
- Phase 0 / task `0.11`: добавлены `RuntimeExecutorBuilder` и `community_default()`, а default community runtime wiring вынесен из `RuntimeExecutor` в отдельный builder layer
|
||||||
- Phase 0 / task `0.13`: введены `RegistryExtension`, `ExtensionMigration` и `apply_extension_migrations(...)` в `crank-registry` как отдельный public seam для additive private migrations
|
- Phase 0 / task `0.13`: введены `RegistryExtension`, `ExtensionMigration` и `apply_extension_migrations(...)` в `crank-registry` как отдельный public seam для additive private migrations
|
||||||
- backward-compatible alias `CommunityMachineCredentialVerifier` сохранен, поведение Community не изменено
|
- backward-compatible alias `CommunityMachineCredentialVerifier` сохранен, поведение Community не изменено
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ use std::sync::Arc;
|
|||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
use base64::{Engine as _, engine::general_purpose::URL_SAFE_NO_PAD};
|
use base64::{Engine as _, engine::general_purpose::URL_SAFE_NO_PAD};
|
||||||
use crank_adapter_rest::RestAdapter;
|
|
||||||
use crank_core::{
|
use crank_core::{
|
||||||
AdapterRegistry, CachedHeader, CachedResponse, ExecutionMode, HttpMethod, ResponseCacheStore,
|
AdapterRegistry, CachedHeader, CachedResponse, ExecutionMode, HttpMethod, ResponseCacheStore,
|
||||||
SharedProtocolAdapter, Target, TransportBehavior,
|
SharedProtocolAdapter, Target, TransportBehavior,
|
||||||
@@ -37,18 +36,28 @@ impl Default for RuntimeExecutor {
|
|||||||
|
|
||||||
impl RuntimeExecutor {
|
impl RuntimeExecutor {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self::with_limits(RuntimeLimits::default())
|
crate::executor_builder::community_default().build()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_limits(limits: RuntimeLimits) -> Self {
|
pub fn with_limits(limits: RuntimeLimits) -> Self {
|
||||||
|
crate::executor_builder::community_default()
|
||||||
|
.with_limits(limits)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn from_builder_parts(
|
||||||
|
limits: RuntimeLimits,
|
||||||
|
adapters: AdapterRegistry,
|
||||||
|
response_cache: Option<Arc<dyn ResponseCacheStore>>,
|
||||||
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
adapters: community_adapter_registry(),
|
adapters,
|
||||||
unary_limiter: Arc::new(Semaphore::new(limits.max_concurrent_unary)),
|
unary_limiter: Arc::new(Semaphore::new(limits.max_concurrent_unary)),
|
||||||
window_limiter: Arc::new(Semaphore::new(limits.max_concurrent_window)),
|
window_limiter: Arc::new(Semaphore::new(limits.max_concurrent_window)),
|
||||||
session_limiter: Arc::new(Semaphore::new(limits.max_concurrent_sessions)),
|
session_limiter: Arc::new(Semaphore::new(limits.max_concurrent_sessions)),
|
||||||
job_limiter: Arc::new(Semaphore::new(limits.max_concurrent_jobs)),
|
job_limiter: Arc::new(Semaphore::new(limits.max_concurrent_jobs)),
|
||||||
limits,
|
limits,
|
||||||
response_cache: None,
|
response_cache,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -514,10 +523,6 @@ impl PreparedRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn community_adapter_registry() -> AdapterRegistry {
|
|
||||||
AdapterRegistry::empty().register(Arc::new(RestAdapter::new()) as SharedProtocolAdapter)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn adapter_request_context(
|
fn adapter_request_context(
|
||||||
request_context: Option<&RuntimeRequestContext>,
|
request_context: Option<&RuntimeRequestContext>,
|
||||||
) -> crank_core::RuntimeRequestContext {
|
) -> crank_core::RuntimeRequestContext {
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use crank_adapter_rest::RestAdapter;
|
||||||
|
use crank_core::{AdapterRegistry, ResponseCacheStore, SharedProtocolAdapter};
|
||||||
|
|
||||||
|
use crate::{RuntimeExecutor, RuntimeLimits};
|
||||||
|
|
||||||
|
pub struct RuntimeExecutorBuilder {
|
||||||
|
limits: RuntimeLimits,
|
||||||
|
adapters: AdapterRegistry,
|
||||||
|
response_cache: Option<Arc<dyn ResponseCacheStore>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl RuntimeExecutorBuilder {
|
||||||
|
pub fn new() -> Self {
|
||||||
|
Self {
|
||||||
|
limits: RuntimeLimits::default(),
|
||||||
|
adapters: AdapterRegistry::empty(),
|
||||||
|
response_cache: None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 build(self) -> RuntimeExecutor {
|
||||||
|
RuntimeExecutor::from_builder_parts(self.limits, self.adapters, self.response_cache)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for RuntimeExecutorBuilder {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self::new()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn community_default() -> RuntimeExecutorBuilder {
|
||||||
|
RuntimeExecutorBuilder::new()
|
||||||
|
.register_adapter(Arc::new(RestAdapter::new()) as SharedProtocolAdapter)
|
||||||
|
}
|
||||||
@@ -3,6 +3,7 @@ mod auth;
|
|||||||
mod cache;
|
mod cache;
|
||||||
mod error;
|
mod error;
|
||||||
mod executor;
|
mod executor;
|
||||||
|
mod executor_builder;
|
||||||
mod limits;
|
mod limits;
|
||||||
mod model;
|
mod model;
|
||||||
mod rate_limit;
|
mod rate_limit;
|
||||||
@@ -19,6 +20,7 @@ pub use cache::{
|
|||||||
};
|
};
|
||||||
pub use error::RuntimeError;
|
pub use error::RuntimeError;
|
||||||
pub use executor::RuntimeExecutor;
|
pub use executor::RuntimeExecutor;
|
||||||
|
pub use executor_builder::{RuntimeExecutorBuilder, community_default};
|
||||||
pub use limits::{RuntimeLimits, RuntimeLimitsConfigError};
|
pub use limits::{RuntimeLimits, RuntimeLimitsConfigError};
|
||||||
pub use model::{AdapterResponse, PreparedRequest, RuntimeOperation};
|
pub use model::{AdapterResponse, PreparedRequest, RuntimeOperation};
|
||||||
pub use rate_limit::{
|
pub use rate_limit::{
|
||||||
|
|||||||
Reference in New Issue
Block a user