fix(bat-api): 完成 issue #19 同机 live 联调
bat-rust / Build and test Go API (push) Canceled after 0s
bat-rust / Build and test Rust (push) Canceled after 0s

This commit is contained in:
2026-08-29 22:58:01 +08:00
parent 90083302a2
commit 7f465523e1
22 changed files with 819 additions and 115 deletions
+6 -2
View File
@@ -24,6 +24,10 @@ pub trait DownloaderBackend<T>: Send + Sync {
fn download(&self, task: T) -> Result<Self::Output, Self::Error>;
}
/// Results returned by a scheduler for a task type and backend.
pub type DownloadResults<T, B> =
Vec<Result<<B as DownloaderBackend<T>>::Output, <B as DownloaderBackend<T>>::Error>>;
/// A bounded worker scheduler.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct DownloadScheduler {
@@ -54,7 +58,7 @@ impl DownloadScheduler {
/// order. A failed task does not cause additional tasks to be scheduled
/// after it, because already-started bounded work must be joined cleanly;
/// callers decide whether a failed result invalidates the whole release.
pub fn execute<T, B>(self, backend: &B, tasks: Vec<T>) -> Vec<Result<B::Output, B::Error>>
pub fn execute<T, B>(self, backend: &B, tasks: Vec<T>) -> DownloadResults<T, B>
where
T: Send + 'static,
B: DownloaderBackend<T>,
@@ -78,7 +82,7 @@ impl DownloadScheduler {
backend: &B,
tasks: Vec<T>,
mut observer: F,
) -> Result<Vec<Result<B::Output, B::Error>>, E>
) -> Result<DownloadResults<T, B>, E>
where
T: Send + 'static,
B: DownloaderBackend<T>,
+7 -6
View File
@@ -38,8 +38,8 @@ pub use curl_transfer::{
redact_proxy_url, resolve_curl_proxy, CurlProxyConfig, CurlProxyMode, ResolvedCurlProxy,
};
pub use downloader::{
DownloadScheduler, DownloaderBackend, DEFAULT_DOWNLOAD_CONCURRENCY, MAX_DOWNLOAD_CONCURRENCY,
MIN_DOWNLOAD_CONCURRENCY,
DownloadResults, DownloadScheduler, DownloaderBackend, DEFAULT_DOWNLOAD_CONCURRENCY,
MAX_DOWNLOAD_CONCURRENCY, MIN_DOWNLOAD_CONCURRENCY,
};
pub use import::{
BundleSource, ImportedResource, ResourceImportCategory, ResourceImportReport,
@@ -136,10 +136,11 @@ pub use release_flow::ReleaseFlowStatusCode;
pub use resources::{InMemoryResourceRepository, SqliteResourceRepository};
pub use translation_tasks::{
build_translation_handoff, read_translation_handoff_at, sync_translation_task_repository_at,
write_translation_handoff_at, PersistedTranslationTask, ProviderRun, ProviderRunStatus,
SqliteTranslationTaskRepository, TranslationHandoff, TranslationJob, TranslationJobStatus,
TranslationTaskStatus, TranslationTaskSyncReport, TranslationUnit, TranslationUnitStatus,
TRANSLATION_HANDOFF_FILE, TRANSLATION_HANDOFF_SCHEMA_VERSION, TRANSLATION_TASK_REPOSITORY_FILE,
write_translation_handoff_at, PersistedTranslationTask, PersistedTranslationTaskState,
ProviderRun, ProviderRunStatus, SqliteTranslationTaskRepository, TranslationHandoff,
TranslationJob, TranslationJobStatus, TranslationTaskStatus, TranslationTaskSyncReport,
TranslationUnit, TranslationUnitStatus, TRANSLATION_HANDOFF_FILE,
TRANSLATION_HANDOFF_SCHEMA_VERSION, TRANSLATION_TASK_REPOSITORY_FILE,
TRANSLATION_TASK_SCHEMA_VERSION,
};
pub use translation_workflow::{
+36 -24
View File
@@ -405,6 +405,25 @@ pub struct PersistedTranslationTask {
pub provider_run_id: Option<String>,
}
/// Mutable persistence metadata associated with an official TextUnit task.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PersistedTranslationTaskState {
/// Current worker state.
pub task_status: TranslationTaskStatus,
/// Provider failure reason, if the worker recorded one.
pub failure_reason: Option<String>,
/// Number of provider attempts.
pub attempt_count: u32,
/// First persistence time as Unix seconds.
pub created_unix_seconds: u64,
/// Last state or metadata update time as Unix seconds.
pub updated_unix_seconds: u64,
/// Completion time as Unix seconds, if completed.
pub completed_unix_seconds: Option<u64>,
/// Provider-side run identifier, if known.
pub provider_run_id: Option<String>,
}
/// Result of synchronizing an immutable release queue into SQLite.
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct TranslationTaskSyncReport {
@@ -860,25 +879,16 @@ type TranslationTaskRow = (
impl PersistedTranslationTask {
/// Builds a persisted translation task from an immutable queue task.
pub fn from_task(
task: OfficialTextUnitTask,
task_status: TranslationTaskStatus,
failure_reason: Option<String>,
attempt_count: u32,
created_unix_seconds: u64,
updated_unix_seconds: u64,
completed_unix_seconds: Option<u64>,
provider_run_id: Option<String>,
) -> Self {
pub fn from_task(task: OfficialTextUnitTask, state: PersistedTranslationTaskState) -> Self {
Self {
task,
task_status,
failure_reason,
attempt_count,
created_unix_seconds,
updated_unix_seconds,
completed_unix_seconds,
provider_run_id,
task_status: state.task_status,
failure_reason: state.failure_reason,
attempt_count: state.attempt_count,
created_unix_seconds: state.created_unix_seconds,
updated_unix_seconds: state.updated_unix_seconds,
completed_unix_seconds: state.completed_unix_seconds,
provider_run_id: state.provider_run_id,
}
}
@@ -892,13 +902,15 @@ impl PersistedTranslationTask {
};
Self::from_task(
task,
task_status,
failure_reason,
0,
generated_unix_seconds,
generated_unix_seconds,
None,
None,
PersistedTranslationTaskState {
task_status,
failure_reason,
attempt_count: 0,
created_unix_seconds: generated_unix_seconds,
updated_unix_seconds: generated_unix_seconds,
completed_unix_seconds: None,
provider_run_id: None,
},
)
}