mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 01:40:21 +08:00
refactor: 抽离 AI pipeline 与调度共享能力逻辑
This commit is contained in:
@@ -90,9 +90,9 @@ impl ProxyNodeReadRepository for InMemoryProxyNodeRepository {
|
||||
.collect::<Vec<_>>();
|
||||
items.sort_by(|left, right| {
|
||||
right
|
||||
.created_at_unix_secs
|
||||
.created_at_unix_ms
|
||||
.unwrap_or(0)
|
||||
.cmp(&left.created_at_unix_secs.unwrap_or(0))
|
||||
.cmp(&left.created_at_unix_ms.unwrap_or(0))
|
||||
.then(right.id.cmp(&left.id))
|
||||
});
|
||||
items.truncate(limit);
|
||||
@@ -191,7 +191,7 @@ impl ProxyNodeWriteRepository for InMemoryProxyNodeRepository {
|
||||
node_id: mutation.node_id.clone(),
|
||||
event_type: event_type.to_string(),
|
||||
detail: Some(format!("[stale_ignored] {event_detail}")),
|
||||
created_at_unix_secs: Self::now_unix_secs(),
|
||||
created_at_unix_ms: Self::now_unix_secs(),
|
||||
});
|
||||
return Ok(Some(node.clone()));
|
||||
}
|
||||
@@ -211,7 +211,7 @@ impl ProxyNodeWriteRepository for InMemoryProxyNodeRepository {
|
||||
node_id: mutation.node_id.clone(),
|
||||
event_type: event_type.to_string(),
|
||||
detail: Some(event_detail),
|
||||
created_at_unix_secs: Some(event_time),
|
||||
created_at_unix_ms: Some(event_time),
|
||||
});
|
||||
Ok(Some(node.clone()))
|
||||
}
|
||||
@@ -341,7 +341,7 @@ mod tests {
|
||||
.expect("list events should succeed");
|
||||
assert_eq!(events.len(), 2);
|
||||
assert_eq!(events[0].event_type, "disconnected");
|
||||
assert_eq!(events[0].created_at_unix_secs, Some(1_800_000_000));
|
||||
assert_eq!(events[0].created_at_unix_ms, Some(1_800_000_000));
|
||||
assert_eq!(
|
||||
events[0].detail.as_deref(),
|
||||
Some("[tunnel_node_status] conn_count=0")
|
||||
@@ -365,14 +365,14 @@ mod tests {
|
||||
node_id: "node-1".to_string(),
|
||||
event_type: "connected".to_string(),
|
||||
detail: Some("older".to_string()),
|
||||
created_at_unix_secs: Some(1_710_000_000),
|
||||
created_at_unix_ms: Some(1_710_000_000),
|
||||
},
|
||||
StoredProxyNodeEvent {
|
||||
id: 2,
|
||||
node_id: "node-1".to_string(),
|
||||
event_type: "disconnected".to_string(),
|
||||
detail: Some("newer".to_string()),
|
||||
created_at_unix_secs: Some(1_710_000_100),
|
||||
created_at_unix_ms: Some(1_710_000_100),
|
||||
},
|
||||
],
|
||||
);
|
||||
|
||||
@@ -39,7 +39,7 @@ SELECT
|
||||
EXTRACT(EPOCH FROM tunnel_connected_at)::bigint AS tunnel_connected_at_unix_secs,
|
||||
remote_config,
|
||||
config_version,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_secs,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_ms,
|
||||
EXTRACT(EPOCH FROM updated_at)::bigint AS updated_at_unix_secs
|
||||
FROM proxy_nodes
|
||||
WHERE id = $1
|
||||
@@ -75,7 +75,7 @@ SELECT
|
||||
EXTRACT(EPOCH FROM tunnel_connected_at)::bigint AS tunnel_connected_at_unix_secs,
|
||||
remote_config,
|
||||
config_version,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_secs,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_ms,
|
||||
EXTRACT(EPOCH FROM updated_at)::bigint AS updated_at_unix_secs
|
||||
FROM proxy_nodes
|
||||
ORDER BY name ASC, id ASC
|
||||
@@ -87,7 +87,7 @@ SELECT
|
||||
node_id,
|
||||
CAST(event_type AS TEXT) AS event_type,
|
||||
detail,
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_secs
|
||||
EXTRACT(EPOCH FROM created_at)::bigint AS created_at_unix_ms
|
||||
FROM proxy_node_events
|
||||
WHERE node_id = $1
|
||||
ORDER BY created_at DESC, id DESC
|
||||
@@ -183,7 +183,7 @@ impl SqlxProxyNodeRepository {
|
||||
.map_postgres_err()?,
|
||||
),
|
||||
row.try_get("remote_config").map_postgres_err()?,
|
||||
Self::optional_unix_secs(row.try_get("created_at_unix_secs").map_postgres_err()?),
|
||||
Self::optional_unix_secs(row.try_get("created_at_unix_ms").map_postgres_err()?),
|
||||
Self::optional_unix_secs(row.try_get("updated_at_unix_secs").map_postgres_err()?),
|
||||
))
|
||||
}
|
||||
@@ -194,8 +194,8 @@ impl SqlxProxyNodeRepository {
|
||||
node_id: row.try_get("node_id").map_postgres_err()?,
|
||||
event_type: row.try_get("event_type").map_postgres_err()?,
|
||||
detail: row.try_get("detail").map_postgres_err()?,
|
||||
created_at_unix_secs: Self::optional_unix_secs(
|
||||
row.try_get("created_at_unix_secs").map_postgres_err()?,
|
||||
created_at_unix_ms: Self::optional_unix_secs(
|
||||
row.try_get("created_at_unix_ms").map_postgres_err()?,
|
||||
),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@ pub struct StoredProxyNode {
|
||||
pub tunnel_connected_at_unix_secs: Option<u64>,
|
||||
pub remote_config: Option<serde_json::Value>,
|
||||
pub config_version: i32,
|
||||
pub created_at_unix_secs: Option<u64>,
|
||||
pub created_at_unix_ms: Option<u64>,
|
||||
pub updated_at_unix_secs: Option<u64>,
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ impl StoredProxyNode {
|
||||
tunnel_connected_at_unix_secs: None,
|
||||
remote_config: None,
|
||||
config_version,
|
||||
created_at_unix_secs: None,
|
||||
created_at_unix_ms: None,
|
||||
updated_at_unix_secs: None,
|
||||
})
|
||||
}
|
||||
@@ -118,7 +118,7 @@ impl StoredProxyNode {
|
||||
estimated_max_concurrency: Option<i32>,
|
||||
tunnel_connected_at_unix_secs: Option<u64>,
|
||||
remote_config: Option<serde_json::Value>,
|
||||
created_at_unix_secs: Option<u64>,
|
||||
created_at_unix_ms: Option<u64>,
|
||||
updated_at_unix_secs: Option<u64>,
|
||||
) -> Self {
|
||||
self.region = region;
|
||||
@@ -130,7 +130,7 @@ impl StoredProxyNode {
|
||||
self.estimated_max_concurrency = estimated_max_concurrency;
|
||||
self.tunnel_connected_at_unix_secs = tunnel_connected_at_unix_secs;
|
||||
self.remote_config = remote_config;
|
||||
self.created_at_unix_secs = created_at_unix_secs;
|
||||
self.created_at_unix_ms = created_at_unix_ms;
|
||||
self.updated_at_unix_secs = updated_at_unix_secs;
|
||||
self
|
||||
}
|
||||
@@ -177,7 +177,7 @@ pub struct StoredProxyNodeEvent {
|
||||
pub node_id: String,
|
||||
pub event_type: String,
|
||||
pub detail: Option<String>,
|
||||
pub created_at_unix_secs: Option<u64>,
|
||||
pub created_at_unix_ms: Option<u64>,
|
||||
}
|
||||
|
||||
pub fn normalize_proxy_metadata(
|
||||
|
||||
Reference in New Issue
Block a user