From 07b28ea8cfa3db2bf97b112fa43b77421eea1766 Mon Sep 17 00:00:00 2001 From: ManyTheFish Date: Wed, 16 Nov 2022 13:47:08 +0100 Subject: [PATCH] Fix task details serialization --- index-scheduler/src/batch.rs | 1 + index-scheduler/src/lib.rs | 1 + meilisearch-http/src/routes/tasks.rs | 4 ++-- meilisearch-types/src/tasks.rs | 21 +++++++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/index-scheduler/src/batch.rs b/index-scheduler/src/batch.rs index 8a2e956cd..38643556a 100644 --- a/index-scheduler/src/batch.rs +++ b/index-scheduler/src/batch.rs @@ -1272,6 +1272,7 @@ impl IndexScheduler { task.status = Status::Canceled; task.canceled_by = Some(cancel_task_id); task.finished_at = Some(now); + task.details = task.details.map(|d| d.to_failed()); self.update_task(wtxn, &task)?; } self.canceled_by.put(wtxn, &BEU32::new(cancel_task_id), &tasks_to_cancel)?; diff --git a/index-scheduler/src/lib.rs b/index-scheduler/src/lib.rs index 1655acdac..9fcc3e54f 100644 --- a/index-scheduler/src/lib.rs +++ b/index-scheduler/src/lib.rs @@ -988,6 +988,7 @@ impl IndexScheduler { task.finished_at = Some(finished_at); task.status = Status::Failed; task.error = Some(error.clone()); + task.details = task.details.map(|d| d.to_failed()); #[cfg(test)] self.maybe_fail(tests::FailureLocation::UpdatingTaskAfterProcessBatchFailure)?; diff --git a/meilisearch-http/src/routes/tasks.rs b/meilisearch-http/src/routes/tasks.rs index 71c774672..3bfe6530d 100644 --- a/meilisearch-http/src/routes/tasks.rs +++ b/meilisearch-http/src/routes/tasks.rs @@ -82,7 +82,7 @@ pub struct DetailsView { #[serde(skip_serializing_if = "Option::is_none")] pub received_documents: Option, #[serde(skip_serializing_if = "Option::is_none")] - pub indexed_documents: Option, + pub indexed_documents: Option>, #[serde(skip_serializing_if = "Option::is_none")] pub primary_key: Option>, #[serde(skip_serializing_if = "Option::is_none")] @@ -112,7 +112,7 @@ impl From
for DetailsView { Details::DocumentAdditionOrUpdate { received_documents, indexed_documents } => { DetailsView { received_documents: Some(received_documents), - indexed_documents, + indexed_documents: Some(indexed_documents), ..DetailsView::default() } } diff --git a/meilisearch-types/src/tasks.rs b/meilisearch-types/src/tasks.rs index fa6673e84..b11ea7a71 100644 --- a/meilisearch-types/src/tasks.rs +++ b/meilisearch-types/src/tasks.rs @@ -474,6 +474,27 @@ pub enum Details { IndexSwap { swaps: Vec }, } +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 /// 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.