Delete a task's persisted data when appropriate

This commit is contained in:
Loïc Lecrenier 2022-10-18 15:04:14 +02:00 committed by Clément Renault
parent 7308ccd530
commit baeb168b6e
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
19 changed files with 116 additions and 11 deletions

View file

@ -381,7 +381,7 @@ impl IndexScheduler {
match wtxn.commit() {
Ok(()) => (),
_e @ Err(_) => {
todo!("remove the data associated with the task");
self.delete_persisted_task_data(&task)?;
// _e?;
}
}
@ -577,8 +577,8 @@ impl IndexScheduler {
for mut task in tasks {
task.started_at = Some(started_at);
task.finished_at = Some(finished_at);
// TODO the info field should've been set by the process_batch function
self.update_task(&mut wtxn, &task)?;
self.delete_persisted_task_data(&task)?;
}
log::info!("A batch of tasks was successfully completed.");
}
@ -606,6 +606,25 @@ impl IndexScheduler {
Ok(processed_tasks)
}
pub(crate) fn delete_persisted_task_data(&self, task: &Task) -> Result<()> {
match &task.kind {
KindWithContent::DocumentImport { content_file, .. } => {
self.delete_update_file(*content_file)
}
KindWithContent::DocumentDeletion { .. }
| KindWithContent::DocumentClear { .. }
| KindWithContent::Settings { .. }
| KindWithContent::IndexDeletion { .. }
| KindWithContent::IndexCreation { .. }
| KindWithContent::IndexUpdate { .. }
| KindWithContent::IndexSwap { .. }
| KindWithContent::CancelTask { .. }
| KindWithContent::TaskDeletion { .. }
| KindWithContent::DumpExport { .. }
| KindWithContent::Snapshot => Ok(()),
}
}
}
#[cfg(test)]