refactor: 抽离 AI pipeline 与调度共享能力逻辑

This commit is contained in:
fawney19
2026-04-10 01:46:14 +08:00
parent b901a6ffc7
commit 5014e2f5fd
255 changed files with 15057 additions and 3115 deletions

View File

@@ -180,8 +180,8 @@ impl VideoTaskReadRepository for InMemoryVideoTaskRepository {
.collect::<Vec<_>>();
tasks.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.updated_at_unix_secs.cmp(&left.updated_at_unix_secs))
});
Ok(tasks.into_iter().skip(offset).take(limit).collect())
@@ -289,7 +289,7 @@ impl VideoTaskReadRepository for InMemoryVideoTaskRepository {
.values()
.filter(|task| {
Self::matches_filter(task, filter)
&& task.created_at_unix_secs >= created_since_unix_secs
&& task.created_at_unix_ms >= created_since_unix_secs
})
.count() as u64)
}
@@ -408,7 +408,7 @@ mod tests {
next_poll_at_unix_secs: Some(updated_at_unix_secs),
poll_count: 0,
max_poll_count: 360,
created_at_unix_secs: updated_at_unix_secs.saturating_sub(10),
created_at_unix_ms: updated_at_unix_secs.saturating_sub(10),
submitted_at_unix_secs: Some(updated_at_unix_secs.saturating_sub(10)),
completed_at_unix_secs: None,
updated_at_unix_secs,
@@ -505,7 +505,7 @@ mod tests {
next_poll_at_unix_secs: Some(200),
poll_count: 2,
max_poll_count: 360,
created_at_unix_secs: 150,
created_at_unix_ms: 150,
submitted_at_unix_secs: Some(150),
completed_at_unix_secs: None,
updated_at_unix_secs: 200,
@@ -590,7 +590,7 @@ mod tests {
model: Some("veo-3-fast".to_string()),
user_id: Some("user-2".to_string()),
client_api_format: Some("gemini:video".to_string()),
created_at_unix_secs: 250,
created_at_unix_ms: 250,
updated_at_unix_secs: 250,
..sample_task("task-2", VideoTaskStatus::Completed, 250)
})
@@ -600,7 +600,7 @@ mod tests {
model: Some("veo-3-fast".to_string()),
user_id: Some("user-2".to_string()),
client_api_format: Some("gemini:video".to_string()),
created_at_unix_secs: 260,
created_at_unix_ms: 260,
updated_at_unix_secs: 260,
..sample_task("task-3", VideoTaskStatus::Completed, 260)
})

View File

@@ -40,7 +40,7 @@ const SELECT_VIDEO_TASK_COLUMNS: &str = r#"
CAST(EXTRACT(EPOCH FROM next_poll_at) AS BIGINT) AS next_poll_at_unix_secs,
poll_count,
max_poll_count,
CAST(EXTRACT(EPOCH FROM created_at) AS BIGINT) AS created_at_unix_secs,
CAST(EXTRACT(EPOCH FROM created_at) AS BIGINT) AS created_at_unix_ms,
CAST(EXTRACT(EPOCH FROM submitted_at) AS BIGINT) AS submitted_at_unix_secs,
CAST(EXTRACT(EPOCH FROM completed_at) AS BIGINT) AS completed_at_unix_secs,
CAST(EXTRACT(EPOCH FROM updated_at) AS BIGINT) AS updated_at_unix_secs,
@@ -599,7 +599,7 @@ impl SqlxVideoTaskRepository {
.bind(task.error_code)
.bind(task.error_message)
.bind(task.request_metadata)
.bind(task.created_at_unix_secs as f64)
.bind(task.created_at_unix_ms as f64)
.bind(task.submitted_at_unix_secs.map(|value| value as f64))
.bind(task.completed_at_unix_secs.map(|value| value as f64))
.bind(task.updated_at_unix_secs as f64)
@@ -668,7 +668,7 @@ impl SqlxVideoTaskRepository {
.bind(task.error_code)
.bind(task.error_message)
.bind(task.request_metadata)
.bind(task.created_at_unix_secs as f64)
.bind(task.created_at_unix_ms as f64)
.bind(task.submitted_at_unix_secs.map(|value| value as f64))
.bind(task.completed_at_unix_secs.map(|value| value as f64))
.bind(task.updated_at_unix_secs as f64)
@@ -917,7 +917,7 @@ fn map_video_task_row(row: &sqlx::postgres::PgRow) -> Result<StoredVideoTask, Da
row.try_get("next_poll_at_unix_secs").map_postgres_err()?,
row.try_get("poll_count").map_postgres_err()?,
row.try_get("max_poll_count").map_postgres_err()?,
row.try_get("created_at_unix_secs").map_postgres_err()?,
row.try_get("created_at_unix_ms").map_postgres_err()?,
row.try_get("submitted_at_unix_secs").map_postgres_err()?,
row.try_get("completed_at_unix_secs").map_postgres_err()?,
row.try_get("updated_at_unix_secs").map_postgres_err()?,
@@ -1017,7 +1017,7 @@ mod tests {
next_poll_at_unix_secs: Some(10),
poll_count: 0,
max_poll_count: 360,
created_at_unix_secs: 1,
created_at_unix_ms: 1,
submitted_at_unix_secs: Some(1),
completed_at_unix_secs: None,
updated_at_unix_secs: 1,
@@ -1065,7 +1065,7 @@ mod tests {
next_poll_at_unix_secs: Some(20),
poll_count: 1,
max_poll_count: 360,
created_at_unix_secs: 1,
created_at_unix_ms: 1,
submitted_at_unix_secs: Some(1),
completed_at_unix_secs: None,
updated_at_unix_secs: 20,