mirror of
https://github.com/fawney19/Aether.git
synced 2026-10-09 18:59:50 +08:00
refactor: 抽离 AI pipeline 与调度共享能力逻辑
This commit is contained in:
@@ -28,9 +28,9 @@ pub(crate) async fn build_admin_provider_endpoints_payload(
|
||||
.unwrap_or_default();
|
||||
endpoints.sort_by(|left, right| {
|
||||
right
|
||||
.created_at_unix_secs
|
||||
.created_at_unix_ms
|
||||
.unwrap_or_default()
|
||||
.cmp(&left.created_at_unix_secs.unwrap_or_default())
|
||||
.cmp(&left.created_at_unix_ms.unwrap_or_default())
|
||||
.then_with(|| left.id.cmp(&right.id))
|
||||
});
|
||||
let keys = state
|
||||
|
||||
@@ -165,7 +165,7 @@ pub(super) async fn handle_admin_provider_oauth_device_authorize(
|
||||
.map(str::trim)
|
||||
.filter(|value| !value.is_empty())
|
||||
.map(ToOwned::to_owned),
|
||||
created_at_unix_secs: now_unix_secs,
|
||||
created_at_unix_ms: now_unix_secs,
|
||||
key_id: None,
|
||||
email: None,
|
||||
replaced: false,
|
||||
|
||||
@@ -128,7 +128,7 @@ pub(crate) async fn create_provider_oauth_catalog_key(
|
||||
record.total_response_time_ms = Some(0);
|
||||
record.health_by_format = Some(json!({}));
|
||||
record.circuit_breaker_by_format = Some(json!({}));
|
||||
record.created_at_unix_secs = Some(now_unix_secs);
|
||||
record.created_at_unix_ms = Some(now_unix_secs);
|
||||
record.updated_at_unix_secs = Some(now_unix_secs);
|
||||
state.create_provider_catalog_key(&record).await
|
||||
}
|
||||
|
||||
@@ -803,7 +803,7 @@ pub(super) fn build_admin_pool_key_payload(
|
||||
);
|
||||
payload.insert(
|
||||
"created_at".to_string(),
|
||||
json!(key.created_at_unix_secs.and_then(unix_secs_to_rfc3339)),
|
||||
json!(key.created_at_unix_ms.and_then(unix_secs_to_rfc3339)),
|
||||
);
|
||||
payload.insert(
|
||||
"last_used_at".to_string(),
|
||||
|
||||
@@ -177,7 +177,7 @@ pub(crate) async fn build_admin_providers_summary_payload(
|
||||
.is_active
|
||||
.cmp(&left.is_active)
|
||||
.then_with(|| left.provider_priority.cmp(&right.provider_priority))
|
||||
.then_with(|| left.created_at_unix_secs.cmp(&right.created_at_unix_secs))
|
||||
.then_with(|| left.created_at_unix_ms.cmp(&right.created_at_unix_ms))
|
||||
});
|
||||
|
||||
let total = providers.len();
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::handlers::admin::request::AdminAppState;
|
||||
use crate::handlers::admin::shared::unix_secs_to_rfc3339;
|
||||
use crate::handlers::public::{request_candidate_event_unix_secs, request_candidate_status_label};
|
||||
use crate::handlers::public::{request_candidate_event_unix_ms, request_candidate_status_label};
|
||||
use crate::handlers::shared::unix_ms_to_rfc3339;
|
||||
use aether_data_contracts::repository::candidates::{
|
||||
RequestCandidateStatus, StoredRequestCandidate,
|
||||
};
|
||||
@@ -82,14 +83,14 @@ pub(crate) async fn build_admin_provider_health_monitor_payload(
|
||||
for candidates in attempts_by_endpoint.values_mut() {
|
||||
candidates.sort_by(|left, right| {
|
||||
right
|
||||
.created_at_unix_secs
|
||||
.cmp(&left.created_at_unix_secs)
|
||||
.created_at_unix_ms
|
||||
.cmp(&left.created_at_unix_ms)
|
||||
.then_with(|| right.id.cmp(&left.id))
|
||||
});
|
||||
candidates.truncate(per_endpoint_limit);
|
||||
candidates.sort_by(|left, right| {
|
||||
request_candidate_event_unix_secs(left)
|
||||
.cmp(&request_candidate_event_unix_secs(right))
|
||||
request_candidate_event_unix_ms(left)
|
||||
.cmp(&request_candidate_event_unix_ms(right))
|
||||
.then_with(|| left.id.cmp(&right.id))
|
||||
});
|
||||
}
|
||||
@@ -118,12 +119,12 @@ pub(crate) async fn build_admin_provider_health_monitor_payload(
|
||||
};
|
||||
let last_event_at = candidates
|
||||
.last()
|
||||
.and_then(|candidate| unix_secs_to_rfc3339(request_candidate_event_unix_secs(candidate)));
|
||||
.and_then(|candidate| unix_ms_to_rfc3339(request_candidate_event_unix_ms(candidate)));
|
||||
let events = candidates
|
||||
.into_iter()
|
||||
.filter_map(|candidate| {
|
||||
Some(json!({
|
||||
"timestamp": unix_secs_to_rfc3339(request_candidate_event_unix_secs(&candidate))?,
|
||||
"timestamp": unix_ms_to_rfc3339(request_candidate_event_unix_ms(&candidate))?,
|
||||
"status": request_candidate_status_label(candidate.status),
|
||||
"status_code": candidate.status_code,
|
||||
"latency_ms": candidate.latency_ms,
|
||||
|
||||
@@ -88,7 +88,7 @@ pub(crate) async fn build_admin_providers_payload(
|
||||
"api_key": has_any_key_by_provider.contains(&provider_id).then_some("***"),
|
||||
"priority": provider.provider_priority,
|
||||
"is_active": provider.is_active,
|
||||
"created_at": provider.created_at_unix_secs.and_then(unix_secs_to_rfc3339),
|
||||
"created_at": provider.created_at_unix_ms.and_then(unix_secs_to_rfc3339),
|
||||
"updated_at": provider.updated_at_unix_secs.and_then(unix_secs_to_rfc3339),
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use crate::handlers::admin::shared::unix_secs_to_rfc3339;
|
||||
use crate::handlers::public::{
|
||||
provider_key_api_formats, request_candidate_event_unix_secs, request_candidate_status_label,
|
||||
provider_key_api_formats, request_candidate_event_unix_ms, request_candidate_status_label,
|
||||
};
|
||||
use aether_data_contracts::repository::candidates::{
|
||||
RequestCandidateStatus, StoredRequestCandidate,
|
||||
@@ -172,7 +172,7 @@ pub(crate) fn build_admin_provider_summary_value(
|
||||
"endpoint_health_details": endpoint_health_details,
|
||||
"ops_configured": ops_configured,
|
||||
"ops_architecture_id": ops_architecture_id,
|
||||
"created_at": endpoint_timestamp_or_now(provider.created_at_unix_secs, now_unix_secs),
|
||||
"created_at": endpoint_timestamp_or_now(provider.created_at_unix_ms, now_unix_secs),
|
||||
"updated_at": endpoint_timestamp_or_now(provider.updated_at_unix_secs, now_unix_secs),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ pub(crate) async fn build_admin_create_provider_key_record(
|
||||
normalize_string_list(payload.model_exclude_patterns).map(|value| json!(value));
|
||||
key.health_by_format = Some(json!({}));
|
||||
key.circuit_breaker_by_format = Some(json!({}));
|
||||
key.created_at_unix_secs = Some(now_unix_secs);
|
||||
key.created_at_unix_ms = Some(now_unix_secs);
|
||||
key.updated_at_unix_secs = Some(now_unix_secs);
|
||||
Ok(key)
|
||||
}
|
||||
|
||||
@@ -24,9 +24,9 @@ pub(crate) async fn build_admin_provider_keys_payload(
|
||||
left.internal_priority
|
||||
.cmp(&right.internal_priority)
|
||||
.then_with(|| {
|
||||
left.created_at_unix_secs
|
||||
left.created_at_unix_ms
|
||||
.unwrap_or_default()
|
||||
.cmp(&right.created_at_unix_secs.unwrap_or_default())
|
||||
.cmp(&right.created_at_unix_ms.unwrap_or_default())
|
||||
})
|
||||
.then_with(|| left.id.cmp(&right.id))
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user