mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-03 01:40:21 +08:00
refactor: 移除独立 hub/proxy/executor/gateway crate,统一为 gateway tunnel 架构
- 删除 aether-hub、aether-proxy 独立项目及其 Dockerfile/配置 - 删除 crates/aether-executor 和 crates/aether-gateway 全部模块 - 新增 apps/ 目录作为应用入口 - 将 hub 概念重构为 gateway tunnel transport - 将 executor 重构为 execution runtime - 新增 tunnel.rs 合约定义和 testkit tunnel/execution_runtime 模块 - 更新 Python 服务层和测试适配新架构命名
This commit is contained in:
165
apps/aether-gateway/src/video_tasks/store/backend.rs
Normal file
165
apps/aether-gateway/src/video_tasks/store/backend.rs
Normal file
@@ -0,0 +1,165 @@
|
||||
use super::*;
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub(crate) struct InMemoryVideoTaskStore {
|
||||
registry: Mutex<VideoTaskRegistry>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub(crate) struct FileVideoTaskStore {
|
||||
path: PathBuf,
|
||||
registry: Mutex<VideoTaskRegistry>,
|
||||
}
|
||||
|
||||
impl VideoTaskStore for InMemoryVideoTaskStore {
|
||||
fn insert(&self, snapshot: LocalVideoTaskSnapshot) {
|
||||
if let Ok(mut registry) = self.registry.lock() {
|
||||
registry.insert(snapshot);
|
||||
}
|
||||
}
|
||||
|
||||
fn read_openai(&self, task_id: &str) -> Option<LocalVideoTaskReadResponse> {
|
||||
let registry = self.registry.lock().ok()?;
|
||||
registry.read_openai(task_id)
|
||||
}
|
||||
|
||||
fn read_gemini(&self, short_id: &str) -> Option<LocalVideoTaskReadResponse> {
|
||||
let registry = self.registry.lock().ok()?;
|
||||
registry.read_gemini(short_id)
|
||||
}
|
||||
|
||||
fn clone_openai(&self, task_id: &str) -> Option<OpenAiVideoTaskSeed> {
|
||||
let registry = self.registry.lock().ok()?;
|
||||
registry.clone_openai(task_id)
|
||||
}
|
||||
|
||||
fn clone_gemini(&self, short_id: &str) -> Option<GeminiVideoTaskSeed> {
|
||||
let registry = self.registry.lock().ok()?;
|
||||
registry.clone_gemini(short_id)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn list_active_snapshots(&self, limit: usize) -> Vec<LocalVideoTaskSnapshot> {
|
||||
let Ok(registry) = self.registry.lock() else {
|
||||
return Vec::new();
|
||||
};
|
||||
registry.list_active_snapshots(limit)
|
||||
}
|
||||
|
||||
fn apply_mutation(&self, mutation: LocalVideoTaskRegistryMutation) {
|
||||
if let Ok(mut registry) = self.registry.lock() {
|
||||
registry.apply_mutation(mutation);
|
||||
}
|
||||
}
|
||||
|
||||
fn project_openai(&self, task_id: &str, provider_body: &Map<String, Value>) -> bool {
|
||||
let Ok(mut registry) = self.registry.lock() else {
|
||||
return false;
|
||||
};
|
||||
registry.project_openai(task_id, provider_body)
|
||||
}
|
||||
|
||||
fn project_gemini(&self, short_id: &str, provider_body: &Map<String, Value>) -> bool {
|
||||
let Ok(mut registry) = self.registry.lock() else {
|
||||
return false;
|
||||
};
|
||||
registry.project_gemini(short_id, provider_body)
|
||||
}
|
||||
}
|
||||
|
||||
impl FileVideoTaskStore {
|
||||
pub(crate) fn new(path: impl Into<PathBuf>) -> std::io::Result<Self> {
|
||||
let path = path.into();
|
||||
let registry = Self::load_registry(&path)?;
|
||||
Ok(Self {
|
||||
path,
|
||||
registry: Mutex::new(registry),
|
||||
})
|
||||
}
|
||||
|
||||
fn load_registry(path: &Path) -> std::io::Result<VideoTaskRegistry> {
|
||||
if !path.exists() {
|
||||
return Ok(VideoTaskRegistry::default());
|
||||
}
|
||||
let bytes = std::fs::read(path)?;
|
||||
if bytes.is_empty() {
|
||||
return Ok(VideoTaskRegistry::default());
|
||||
}
|
||||
serde_json::from_slice(&bytes)
|
||||
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))
|
||||
}
|
||||
|
||||
fn persist_registry(&self, registry: &VideoTaskRegistry) -> std::io::Result<()> {
|
||||
if let Some(parent) = self.path.parent() {
|
||||
std::fs::create_dir_all(parent)?;
|
||||
}
|
||||
let bytes = serde_json::to_vec_pretty(registry)
|
||||
.map_err(|err| std::io::Error::new(std::io::ErrorKind::InvalidData, err))?;
|
||||
let temp_path = self.path.with_extension("tmp");
|
||||
std::fs::write(&temp_path, bytes)?;
|
||||
std::fs::rename(temp_path, &self.path)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn mutate_registry(&self, mutator: impl FnOnce(&mut VideoTaskRegistry) -> bool) -> bool {
|
||||
let Ok(mut registry) = self.registry.lock() else {
|
||||
return false;
|
||||
};
|
||||
if !mutator(&mut registry) {
|
||||
return false;
|
||||
}
|
||||
self.persist_registry(®istry).is_ok()
|
||||
}
|
||||
}
|
||||
|
||||
impl VideoTaskStore for FileVideoTaskStore {
|
||||
fn insert(&self, snapshot: LocalVideoTaskSnapshot) {
|
||||
let _ = self.mutate_registry(|registry| {
|
||||
registry.insert(snapshot);
|
||||
true
|
||||
});
|
||||
}
|
||||
|
||||
fn read_openai(&self, task_id: &str) -> Option<LocalVideoTaskReadResponse> {
|
||||
let registry = self.registry.lock().ok()?;
|
||||
registry.read_openai(task_id)
|
||||
}
|
||||
|
||||
fn read_gemini(&self, short_id: &str) -> Option<LocalVideoTaskReadResponse> {
|
||||
let registry = self.registry.lock().ok()?;
|
||||
registry.read_gemini(short_id)
|
||||
}
|
||||
|
||||
fn clone_openai(&self, task_id: &str) -> Option<OpenAiVideoTaskSeed> {
|
||||
let registry = self.registry.lock().ok()?;
|
||||
registry.clone_openai(task_id)
|
||||
}
|
||||
|
||||
fn clone_gemini(&self, short_id: &str) -> Option<GeminiVideoTaskSeed> {
|
||||
let registry = self.registry.lock().ok()?;
|
||||
registry.clone_gemini(short_id)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
fn list_active_snapshots(&self, limit: usize) -> Vec<LocalVideoTaskSnapshot> {
|
||||
let Ok(registry) = self.registry.lock() else {
|
||||
return Vec::new();
|
||||
};
|
||||
registry.list_active_snapshots(limit)
|
||||
}
|
||||
|
||||
fn apply_mutation(&self, mutation: LocalVideoTaskRegistryMutation) {
|
||||
let _ = self.mutate_registry(|registry| {
|
||||
registry.apply_mutation(mutation);
|
||||
true
|
||||
});
|
||||
}
|
||||
|
||||
fn project_openai(&self, task_id: &str, provider_body: &Map<String, Value>) -> bool {
|
||||
self.mutate_registry(|registry| registry.project_openai(task_id, provider_body))
|
||||
}
|
||||
|
||||
fn project_gemini(&self, short_id: &str, provider_body: &Map<String, Value>) -> bool {
|
||||
self.mutate_registry(|registry| registry.project_gemini(short_id, provider_body))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user