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:
+69
-2
@@ -400,7 +400,7 @@ impl AppState {
|
||||
|
||||
/// Deletes a finished call: both audio files and the row, and takes it
|
||||
/// out of the prompt queue. Returns how many calls still wait for the
|
||||
/// prompt.
|
||||
/// prompt. A call that is being processed is not deleted.
|
||||
pub fn discard_call(&self, id: CallId) -> Result<usize, String> {
|
||||
if lock(&self.current)
|
||||
.as_ref()
|
||||
@@ -408,11 +408,19 @@ impl AppState {
|
||||
{
|
||||
return Err("Das Gespräch wird gerade aufgenommen".to_string());
|
||||
}
|
||||
// Held until the call is gone, so no run can claim it meanwhile.
|
||||
let processing = lock(&self.processing);
|
||||
if processing.contains(&id) {
|
||||
return Err(ALREADY_PROCESSING.to_string());
|
||||
}
|
||||
let call = self
|
||||
.store
|
||||
.get_call(id)
|
||||
.map_err(|e| e.to_string())?
|
||||
.ok_or_else(|| "Gespräch nicht gefunden".to_string())?;
|
||||
if call.status == CallStatus::Processing {
|
||||
return Err(ALREADY_PROCESSING.to_string());
|
||||
}
|
||||
// Files first: if one cannot be deleted, the row stays so the user
|
||||
// can try again instead of leaving orphaned audio behind.
|
||||
for path in [&call.mic_path, &call.out_path] {
|
||||
@@ -438,6 +446,7 @@ impl AppState {
|
||||
}
|
||||
return Err(format!("Gespräch konnte nicht gelöscht werden: {e}"));
|
||||
}
|
||||
drop(processing);
|
||||
Ok(self.prompts_waiting())
|
||||
}
|
||||
|
||||
@@ -470,7 +479,15 @@ impl AppState {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Ends the pipeline run claimed by [`AppState::claim_processing`].
|
||||
/// Reserves `id` for a cleanup of its remote jobs, whatever its status;
|
||||
/// `false` if a run or cleanup already has it. Release it with
|
||||
/// [`AppState::release_processing`].
|
||||
pub fn reserve_processing(&self, id: CallId) -> bool {
|
||||
lock(&self.processing).insert(id)
|
||||
}
|
||||
|
||||
/// Ends the pipeline run claimed by [`AppState::claim_processing`] (or
|
||||
/// the cleanup reserved by [`AppState::reserve_processing`]).
|
||||
pub fn release_processing(&self, id: CallId) {
|
||||
lock(&self.processing).remove(&id);
|
||||
}
|
||||
@@ -707,6 +724,56 @@ mod tests {
|
||||
assert_eq!(f.state.prompts_waiting(), 0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_call_being_processed_is_not_discarded() {
|
||||
let f = fixture();
|
||||
let (id, mic, out) = finished_call(&f, "a");
|
||||
f.state.queue_prompt(id);
|
||||
f.state.claim_processing(id, false).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
f.state.discard_call(id),
|
||||
Err("Wird bereits verarbeitet".to_string())
|
||||
);
|
||||
f.state.release_processing(id);
|
||||
f.state
|
||||
.store
|
||||
.set_status(id, CallStatus::Processing, None)
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
f.state.discard_call(id),
|
||||
Err("Wird bereits verarbeitet".to_string())
|
||||
);
|
||||
|
||||
assert!(mic.exists());
|
||||
assert!(out.exists());
|
||||
assert!(f.state.store.get_call(id).unwrap().is_some());
|
||||
assert_eq!(f.state.prompts_waiting(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_cleanup_reserves_a_call_of_any_status() {
|
||||
let f = fixture();
|
||||
let (id, _, _) = finished_call(&f, "a");
|
||||
f.state
|
||||
.store
|
||||
.set_status(id, CallStatus::Done, None)
|
||||
.unwrap();
|
||||
|
||||
assert!(f.state.reserve_processing(id));
|
||||
assert!(!f.state.reserve_processing(id));
|
||||
f.state
|
||||
.store
|
||||
.set_status(id, CallStatus::Failed, Some("Fehler"))
|
||||
.unwrap();
|
||||
assert_eq!(
|
||||
f.state.claim_processing(id, true),
|
||||
Err("Wird bereits verarbeitet".to_string())
|
||||
);
|
||||
f.state.release_processing(id);
|
||||
assert!(f.state.reserve_processing(id));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_call_is_processed_once_at_a_time() {
|
||||
let f = fixture();
|
||||
|
||||
Reference in New Issue
Block a user