From 3a90233a3d4daff889e690d1657f4c6330942cdd Mon Sep 17 00:00:00 2001 From: qdequele Date: Thu, 28 Nov 2019 18:27:08 +0100 Subject: [PATCH] Add status failed on UpdateStatus --- meilisearch-core/src/database.rs | 4 ++-- meilisearch-core/src/update/mod.rs | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/meilisearch-core/src/database.rs b/meilisearch-core/src/database.rs index c6f5ede90..ea57c7d14 100644 --- a/meilisearch-core/src/database.rs +++ b/meilisearch-core/src/database.rs @@ -461,7 +461,7 @@ mod tests { let update_reader = db.update_read_txn().unwrap(); let result = index.update_status(&update_reader, update_id).unwrap(); - assert_matches!(result, Some(UpdateStatus::Processed { content }) if content.error.is_some()); + assert_matches!(result, Some(UpdateStatus::Failed { content }) if content.error.is_some()); } #[test] @@ -685,7 +685,7 @@ mod tests { // check if it has been accepted let update_reader = db.update_read_txn().unwrap(); let result = index.update_status(&update_reader, update_id).unwrap(); - assert_matches!(result, Some(UpdateStatus::Processed { content }) if content.error.is_some()); + assert_matches!(result, Some(UpdateStatus::Failed { content }) if content.error.is_some()); } #[test] diff --git a/meilisearch-core/src/update/mod.rs b/meilisearch-core/src/update/mod.rs index 3ac39bf0b..dee681cdf 100644 --- a/meilisearch-core/src/update/mod.rs +++ b/meilisearch-core/src/update/mod.rs @@ -197,6 +197,10 @@ pub enum UpdateStatus { #[serde(flatten)] content: EnqueuedUpdateResult, }, + Failed { + #[serde(flatten)] + content: ProcessedUpdateResult, + }, Processed { #[serde(flatten)] content: ProcessedUpdateResult, @@ -210,7 +214,13 @@ pub fn update_status( update_id: u64, ) -> MResult> { match updates_results_store.update_result(update_reader, update_id)? { - Some(result) => Ok(Some(UpdateStatus::Processed { content: result })), + Some(result) => { + if result.error.is_some() { + Ok(Some(UpdateStatus::Failed { content: result })) + } else { + Ok(Some(UpdateStatus::Processed { content: result })) + } + }, None => match updates_store.get(update_reader, update_id)? { Some(update) => Ok(Some(UpdateStatus::Enqueued { content: EnqueuedUpdateResult {