Fix task details serialization

This commit is contained in:
ManyTheFish 2022-11-16 13:47:08 +01:00
parent 51be75a264
commit 07b28ea8cf
4 changed files with 25 additions and 2 deletions

View File

@ -1272,6 +1272,7 @@ impl IndexScheduler {
task.status = Status::Canceled; task.status = Status::Canceled;
task.canceled_by = Some(cancel_task_id); task.canceled_by = Some(cancel_task_id);
task.finished_at = Some(now); task.finished_at = Some(now);
task.details = task.details.map(|d| d.to_failed());
self.update_task(wtxn, &task)?; self.update_task(wtxn, &task)?;
} }
self.canceled_by.put(wtxn, &BEU32::new(cancel_task_id), &tasks_to_cancel)?; self.canceled_by.put(wtxn, &BEU32::new(cancel_task_id), &tasks_to_cancel)?;

View File

@ -988,6 +988,7 @@ impl IndexScheduler {
task.finished_at = Some(finished_at); task.finished_at = Some(finished_at);
task.status = Status::Failed; task.status = Status::Failed;
task.error = Some(error.clone()); task.error = Some(error.clone());
task.details = task.details.map(|d| d.to_failed());
#[cfg(test)] #[cfg(test)]
self.maybe_fail(tests::FailureLocation::UpdatingTaskAfterProcessBatchFailure)?; self.maybe_fail(tests::FailureLocation::UpdatingTaskAfterProcessBatchFailure)?;

View File

@ -82,7 +82,7 @@ pub struct DetailsView {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub received_documents: Option<u64>, pub received_documents: Option<u64>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub indexed_documents: Option<u64>, pub indexed_documents: Option<Option<u64>>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub primary_key: Option<Option<String>>, pub primary_key: Option<Option<String>>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
@ -112,7 +112,7 @@ impl From<Details> for DetailsView {
Details::DocumentAdditionOrUpdate { received_documents, indexed_documents } => { Details::DocumentAdditionOrUpdate { received_documents, indexed_documents } => {
DetailsView { DetailsView {
received_documents: Some(received_documents), received_documents: Some(received_documents),
indexed_documents, indexed_documents: Some(indexed_documents),
..DetailsView::default() ..DetailsView::default()
} }
} }

View File

@ -474,6 +474,27 @@ pub enum Details {
IndexSwap { swaps: Vec<IndexSwap> }, IndexSwap { swaps: Vec<IndexSwap> },
} }
impl Details {
pub fn to_failed(&self) -> Self {
let mut details = self.clone();
match &mut details {
Self::DocumentAdditionOrUpdate { indexed_documents, .. } => {
*indexed_documents = Some(0)
}
Self::DocumentDeletion { deleted_documents, .. } => *deleted_documents = Some(0),
Self::ClearAll { deleted_documents } => *deleted_documents = Some(0),
Self::TaskCancelation { canceled_tasks, .. } => *canceled_tasks = Some(0),
Self::TaskDeletion { deleted_tasks, .. } => *deleted_tasks = Some(0),
Self::SettingsUpdate { .. }
| Self::IndexInfo { .. }
| Self::Dump { .. }
| Self::IndexSwap { .. } => (),
}
details
}
}
/// Serialize a `time::Duration` as a best effort ISO 8601 while waiting for /// Serialize a `time::Duration` as a best effort ISO 8601 while waiting for
/// https://github.com/time-rs/time/issues/378. /// https://github.com/time-rs/time/issues/378.
/// This code is a port of the old code of time that was removed in 0.2. /// This code is a port of the old code of time that was removed in 0.2.