fix #14740: always clean up deepscript jobs and upload copies
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
+43
-11
@@ -3,6 +3,9 @@
|
||||
//! system notification when a run ends. Notifications never contain
|
||||
//! transcript text, and the API key is never logged.
|
||||
|
||||
use std::io::ErrorKind;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use recorder_core::model::{CallId, CallStatus};
|
||||
use recorder_core::pipeline::{self, PipelineOptions};
|
||||
use recorder_core::secrets::Service;
|
||||
@@ -36,6 +39,16 @@ impl Claim {
|
||||
id,
|
||||
})
|
||||
}
|
||||
|
||||
/// Reserves the call for a cleanup ([`AppState::reserve_processing`]).
|
||||
fn for_cleanup(app: &AppHandle, id: CallId) -> Option<Self> {
|
||||
app.state::<AppState>()
|
||||
.reserve_processing(id)
|
||||
.then(|| Self {
|
||||
app: app.clone(),
|
||||
id,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for Claim {
|
||||
@@ -60,11 +73,7 @@ pub fn start(app: &AppHandle, id: CallId, retry: bool) -> Result<(), String> {
|
||||
emit_updated(app, id);
|
||||
return Err(msg);
|
||||
};
|
||||
let work_dir = app
|
||||
.path()
|
||||
.app_cache_dir()
|
||||
.map_err(|e| format!("Cache-Ordner nicht gefunden: {e}"))?
|
||||
.join("upload");
|
||||
let work_dir = upload_dir(app)?;
|
||||
let settings = state.settings();
|
||||
let opts = PipelineOptions {
|
||||
language: settings.language,
|
||||
@@ -95,11 +104,34 @@ pub fn start(app: &AppHandle, id: CallId, retry: bool) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Best-effort deletes the DeepScript jobs of calls whose processing the
|
||||
/// last run of the app did not finish ([`RecoveryReport::failed`]), in the
|
||||
/// Where the pipeline puts the FLAC copies it uploads.
|
||||
fn upload_dir(app: &AppHandle) -> Result<PathBuf, String> {
|
||||
app.path()
|
||||
.app_cache_dir()
|
||||
.map(|dir| dir.join("upload"))
|
||||
.map_err(|e| format!("Cache-Ordner nicht gefunden: {e}"))
|
||||
}
|
||||
|
||||
/// Removes FLAC copies left in the upload directory by a run the app did
|
||||
/// not finish. Call before any run can start.
|
||||
pub fn clear_upload_dir(app: &AppHandle) {
|
||||
let dir = match upload_dir(app) {
|
||||
Ok(dir) => dir,
|
||||
Err(e) => {
|
||||
log::warn!("{e}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
match std::fs::remove_dir_all(&dir) {
|
||||
Ok(()) => log::info!("removed leftover uploads in {}", dir.display()),
|
||||
Err(e) if e.kind() == ErrorKind::NotFound => {}
|
||||
Err(e) => log::warn!("could not empty {}: {e}", dir.display()),
|
||||
}
|
||||
}
|
||||
|
||||
/// Best-effort deletes the DeepScript jobs still on record for `calls`
|
||||
/// (from runs the app did not finish, or whose delete failed), in the
|
||||
/// background. Skipped without a key.
|
||||
///
|
||||
/// [`RecoveryReport::failed`]: recorder_core::store::RecoveryReport::failed
|
||||
pub fn delete_leftover_jobs(app: &AppHandle, calls: Vec<CallId>) {
|
||||
if calls.is_empty() {
|
||||
return;
|
||||
@@ -117,8 +149,8 @@ pub fn delete_leftover_jobs(app: &AppHandle, calls: Vec<CallId>) {
|
||||
let state = app.state::<AppState>();
|
||||
let transcriber = DeepScript::new(state.transport.clone(), key);
|
||||
for id in calls {
|
||||
// A retry the user started meanwhile cleans up itself.
|
||||
let Ok(_claim) = Claim::take(&app, id, true) else {
|
||||
// A run the user started meanwhile cleans up itself.
|
||||
let Some(_claim) = Claim::for_cleanup(&app, id) else {
|
||||
continue;
|
||||
};
|
||||
pipeline::delete_remote_jobs(&state.store, &transcriber, id).await;
|
||||
|
||||
Reference in New Issue
Block a user