Rename the Tasks Types

This commit is contained in:
Kerollmops 2022-05-25 12:05:24 +02:00
parent 8509243e68
commit 3f80468f18
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
5 changed files with 75 additions and 96 deletions

View File

@ -1,7 +1,6 @@
use actix_web::{web, HttpRequest, HttpResponse}; use actix_web::{web, HttpRequest, HttpResponse};
use meilisearch_error::ResponseError; use meilisearch_error::ResponseError;
use meilisearch_lib::milli::update::IndexDocumentsMethod; use meilisearch_lib::tasks::task::{TaskContent, TaskEvent, TaskId};
use meilisearch_lib::tasks::task::{DocumentDeletion, TaskContent, TaskEvent, TaskId};
use meilisearch_lib::tasks::TaskFilter; use meilisearch_lib::tasks::TaskFilter;
use meilisearch_lib::{IndexUid, MeiliSearch}; use meilisearch_lib::{IndexUid, MeiliSearch};
use serde::Deserialize; use serde::Deserialize;
@ -30,34 +29,23 @@ pub struct TaskFilterQuery {
#[rustfmt::skip] #[rustfmt::skip]
fn task_type_matches_content(type_: &TaskType, content: &TaskContent) -> bool { fn task_type_matches_content(type_: &TaskType, content: &TaskContent) -> bool {
matches!((type_, content), matches!((type_, content),
(TaskType::IndexCreation, TaskContent::IndexCreation { .. }) (TaskType::IndexCreation, TaskContent::IndexCreation { .. })
| (TaskType::IndexUpdate, TaskContent::IndexUpdate { .. }) | (TaskType::IndexUpdate, TaskContent::IndexUpdate { .. })
| (TaskType::IndexDeletion, TaskContent::IndexDeletion) | (TaskType::IndexDeletion, TaskContent::IndexDeletion)
| (TaskType::DocumentAddition, TaskContent::DocumentAddition { | (TaskType::DocumentAdditionOrUpdate, TaskContent::DocumentAddition { .. })
merge_strategy: IndexDocumentsMethod::ReplaceDocuments, | (TaskType::DocumentDeletion, TaskContent::DocumentDeletion(_))
..
})
| (TaskType::DocumentPartial, TaskContent::DocumentAddition {
merge_strategy: IndexDocumentsMethod::UpdateDocuments,
..
})
| (TaskType::DocumentDeletion, TaskContent::DocumentDeletion(DocumentDeletion::Ids(_)))
| (TaskType::SettingsUpdate, TaskContent::SettingsUpdate { .. }) | (TaskType::SettingsUpdate, TaskContent::SettingsUpdate { .. })
| (TaskType::ClearAll, TaskContent::DocumentDeletion(DocumentDeletion::Clear))
) )
} }
#[rustfmt::skip]
fn task_status_matches_events(status: &TaskStatus, events: &[TaskEvent]) -> bool { fn task_status_matches_events(status: &TaskStatus, events: &[TaskEvent]) -> bool {
events.last().map_or(false, |event| { events.last().map_or(false, |event| {
matches!( matches!((status, event),
(status, event), (TaskStatus::Enqueued, TaskEvent::Created(_))
(TaskStatus::Enqueued, TaskEvent::Created(_)) | (TaskStatus::Processing, TaskEvent::Processing(_) | TaskEvent::Batched { .. })
| ( | (TaskStatus::Succeeded, TaskEvent::Succeded { .. })
TaskStatus::Processing, | (TaskStatus::Failed, TaskEvent::Failed { .. }),
TaskEvent::Processing(_) | TaskEvent::Batched { .. }
)
| (TaskStatus::Succeeded, TaskEvent::Succeded { .. })
| (TaskStatus::Failed, TaskEvent::Failed { .. }),
) )
}) })
} }

View File

@ -4,7 +4,6 @@ use std::write;
use meilisearch_error::ResponseError; use meilisearch_error::ResponseError;
use meilisearch_lib::index::{Settings, Unchecked}; use meilisearch_lib::index::{Settings, Unchecked};
use meilisearch_lib::milli::update::IndexDocumentsMethod;
use meilisearch_lib::tasks::batch::BatchId; use meilisearch_lib::tasks::batch::BatchId;
use meilisearch_lib::tasks::task::{ use meilisearch_lib::tasks::task::{
DocumentDeletion, Task, TaskContent, TaskEvent, TaskId, TaskResult, DocumentDeletion, Task, TaskContent, TaskEvent, TaskId, TaskResult,
@ -20,33 +19,22 @@ pub enum TaskType {
IndexCreation, IndexCreation,
IndexUpdate, IndexUpdate,
IndexDeletion, IndexDeletion,
DocumentAddition, DocumentAdditionOrUpdate,
DocumentPartial,
DocumentDeletion, DocumentDeletion,
SettingsUpdate, SettingsUpdate,
ClearAll,
DumpCreation, DumpCreation,
} }
impl From<TaskContent> for TaskType { impl From<TaskContent> for TaskType {
fn from(other: TaskContent) -> Self { fn from(other: TaskContent) -> Self {
match other { match other {
TaskContent::DocumentAddition {
merge_strategy: IndexDocumentsMethod::ReplaceDocuments,
..
} => TaskType::DocumentAddition,
TaskContent::DocumentAddition {
merge_strategy: IndexDocumentsMethod::UpdateDocuments,
..
} => TaskType::DocumentPartial,
TaskContent::DocumentDeletion(DocumentDeletion::Clear) => TaskType::ClearAll,
TaskContent::DocumentDeletion(DocumentDeletion::Ids(_)) => TaskType::DocumentDeletion,
TaskContent::SettingsUpdate { .. } => TaskType::SettingsUpdate,
TaskContent::IndexDeletion => TaskType::IndexDeletion,
TaskContent::IndexCreation { .. } => TaskType::IndexCreation, TaskContent::IndexCreation { .. } => TaskType::IndexCreation,
TaskContent::IndexUpdate { .. } => TaskType::IndexUpdate, TaskContent::IndexUpdate { .. } => TaskType::IndexUpdate,
TaskContent::IndexDeletion => TaskType::IndexDeletion,
TaskContent::DocumentAddition { .. } => TaskType::DocumentAdditionOrUpdate,
TaskContent::DocumentDeletion(_) => TaskType::DocumentDeletion,
TaskContent::SettingsUpdate { .. } => TaskType::SettingsUpdate,
TaskContent::Dump { .. } => TaskType::DumpCreation, TaskContent::Dump { .. } => TaskType::DumpCreation,
_ => unreachable!("unexpected task type"),
} }
} }
} }
@ -55,21 +43,27 @@ impl FromStr for TaskType {
type Err = String; type Err = String;
fn from_str(status: &str) -> Result<Self, String> { fn from_str(status: &str) -> Result<Self, String> {
match status { if status.eq_ignore_ascii_case("indexCreation") {
"indexCreation" => Ok(TaskType::IndexCreation), Ok(TaskType::IndexCreation)
"indexUpdate" => Ok(TaskType::IndexUpdate), } else if status.eq_ignore_ascii_case("indexUpdate") {
"indexDeletion" => Ok(TaskType::IndexDeletion), Ok(TaskType::IndexUpdate)
"documentAddition" => Ok(TaskType::DocumentAddition), } else if status.eq_ignore_ascii_case("indexDeletion") {
"documentPartial" => Ok(TaskType::DocumentPartial), Ok(TaskType::IndexDeletion)
"documentDeletion" => Ok(TaskType::DocumentDeletion), } else if status.eq_ignore_ascii_case("documentAdditionOrUpdate") {
"settingsUpdate" => Ok(TaskType::SettingsUpdate), Ok(TaskType::DocumentAdditionOrUpdate)
"clearAll" => Ok(TaskType::ClearAll), } else if status.eq_ignore_ascii_case("documentDeletion") {
unknown => Err(format!( Ok(TaskType::DocumentDeletion)
"invalid task type `{}` value, expecting one of: \ } else if status.eq_ignore_ascii_case("settingsUpdate") {
indexCreation, indexUpdate, indexDeletion, documentAddition, \ Ok(TaskType::SettingsUpdate)
documentPartial, documentDeletion, settingsUpdate, or clearAll", } else if status.eq_ignore_ascii_case("dumpCreation") {
unknown Ok(TaskType::DumpCreation)
)), } else {
Err(format!(
"invalid task type `{}`, expecting one of: \
indexCreation, indexUpdate, indexDeletion, documentAdditionOrUpdate, \
documentDeletion, settingsUpdate, dumpCreation",
status
))
} }
} }
} }
@ -87,16 +81,20 @@ impl FromStr for TaskStatus {
type Err = String; type Err = String;
fn from_str(status: &str) -> Result<Self, String> { fn from_str(status: &str) -> Result<Self, String> {
match status { if status.eq_ignore_ascii_case("enqueued") {
"enqueued" => Ok(TaskStatus::Enqueued), Ok(TaskStatus::Enqueued)
"processing" => Ok(TaskStatus::Processing), } else if status.eq_ignore_ascii_case("processing") {
"succeeded" => Ok(TaskStatus::Succeeded), Ok(TaskStatus::Processing)
"failed" => Ok(TaskStatus::Failed), } else if status.eq_ignore_ascii_case("succeeded") {
unknown => Err(format!( Ok(TaskStatus::Succeeded)
"invalid task status `{}` value, expecting one of: \ } else if status.eq_ignore_ascii_case("failed") {
Ok(TaskStatus::Failed)
} else {
Err(format!(
"invalid task status `{}`, expecting one of: \
enqueued, processing, succeeded, or failed", enqueued, processing, succeeded, or failed",
unknown status,
)), ))
} }
} }
} }
@ -214,22 +212,14 @@ impl From<Task> for TaskView {
let (task_type, mut details) = match content { let (task_type, mut details) = match content {
TaskContent::DocumentAddition { TaskContent::DocumentAddition {
merge_strategy, documents_count, ..
documents_count,
..
} => { } => {
let details = TaskDetails::DocumentAddition { let details = TaskDetails::DocumentAddition {
received_documents: documents_count, received_documents: documents_count,
indexed_documents: None, indexed_documents: None,
}; };
let task_type = match merge_strategy { (TaskType::DocumentAdditionOrUpdate, Some(details))
IndexDocumentsMethod::UpdateDocuments => TaskType::DocumentPartial,
IndexDocumentsMethod::ReplaceDocuments => TaskType::DocumentAddition,
_ => unreachable!("Unexpected document merge strategy."),
};
(task_type, Some(details))
} }
TaskContent::DocumentDeletion(DocumentDeletion::Ids(ids)) => ( TaskContent::DocumentDeletion(DocumentDeletion::Ids(ids)) => (
TaskType::DocumentDeletion, TaskType::DocumentDeletion,
@ -239,7 +229,7 @@ impl From<Task> for TaskView {
}), }),
), ),
TaskContent::DocumentDeletion(DocumentDeletion::Clear) => ( TaskContent::DocumentDeletion(DocumentDeletion::Clear) => (
TaskType::ClearAll, TaskType::DocumentDeletion,
Some(TaskDetails::ClearAll { Some(TaskDetails::ClearAll {
deleted_documents: None, deleted_documents: None,
}), }),

View File

@ -615,7 +615,7 @@ async fn add_documents_no_index_creation() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["status"], "succeeded"); assert_eq!(response["status"], "succeeded");
assert_eq!(response["uid"], 0); assert_eq!(response["uid"], 0);
assert_eq!(response["type"], "documentAddition"); assert_eq!(response["type"], "documentAdditionOrUpdate");
assert_eq!(response["details"]["receivedDocuments"], 1); assert_eq!(response["details"]["receivedDocuments"], 1);
assert_eq!(response["details"]["indexedDocuments"], 1); assert_eq!(response["details"]["indexedDocuments"], 1);
@ -685,7 +685,7 @@ async fn document_addition_with_primary_key() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["status"], "succeeded"); assert_eq!(response["status"], "succeeded");
assert_eq!(response["uid"], 0); assert_eq!(response["uid"], 0);
assert_eq!(response["type"], "documentAddition"); assert_eq!(response["type"], "documentAdditionOrUpdate");
assert_eq!(response["details"]["receivedDocuments"], 1); assert_eq!(response["details"]["receivedDocuments"], 1);
assert_eq!(response["details"]["indexedDocuments"], 1); assert_eq!(response["details"]["indexedDocuments"], 1);
@ -714,7 +714,7 @@ async fn document_update_with_primary_key() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["status"], "succeeded"); assert_eq!(response["status"], "succeeded");
assert_eq!(response["uid"], 0); assert_eq!(response["uid"], 0);
assert_eq!(response["type"], "documentPartial"); assert_eq!(response["type"], "documentAdditionOrUpdate");
assert_eq!(response["details"]["indexedDocuments"], 1); assert_eq!(response["details"]["indexedDocuments"], 1);
assert_eq!(response["details"]["receivedDocuments"], 1); assert_eq!(response["details"]["receivedDocuments"], 1);
@ -818,7 +818,7 @@ async fn add_larger_dataset() {
let (response, code) = index.get_task(update_id).await; let (response, code) = index.get_task(update_id).await;
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["status"], "succeeded"); assert_eq!(response["status"], "succeeded");
assert_eq!(response["type"], "documentAddition"); assert_eq!(response["type"], "documentAdditionOrUpdate");
assert_eq!(response["details"]["indexedDocuments"], 77); assert_eq!(response["details"]["indexedDocuments"], 77);
assert_eq!(response["details"]["receivedDocuments"], 77); assert_eq!(response["details"]["receivedDocuments"], 77);
let (response, code) = index let (response, code) = index
@ -840,7 +840,7 @@ async fn update_larger_dataset() {
index.wait_task(0).await; index.wait_task(0).await;
let (response, code) = index.get_task(0).await; let (response, code) = index.get_task(0).await;
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!(response["type"], "documentPartial"); assert_eq!(response["type"], "documentAdditionOrUpdate");
assert_eq!(response["details"]["indexedDocuments"], 77); assert_eq!(response["details"]["indexedDocuments"], 77);
let (response, code) = index let (response, code) = index
.get_all_documents(GetAllDocumentsOptions { .get_all_documents(GetAllDocumentsOptions {

View File

@ -69,7 +69,7 @@ async fn import_dump_v2_movie_raw() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!( assert_eq!(
tasks, tasks,
json!({ "results": [{"uid": 0, "indexUid": "indexUID", "status": "succeeded", "type": "documentAddition", "details": { "receivedDocuments": 0, "indexedDocuments": 31944 }, "duration": "PT41.751156S", "enqueuedAt": "2021-09-08T08:30:30.550282Z", "startedAt": "2021-09-08T08:30:30.553012Z", "finishedAt": "2021-09-08T08:31:12.304168Z"}]}) json!({ "results": [{"uid": 0, "indexUid": "indexUID", "status": "succeeded", "type": "documentAdditionOrUpdate", "details": { "receivedDocuments": 0, "indexedDocuments": 31944 }, "duration": "PT41.751156S", "enqueuedAt": "2021-09-08T08:30:30.550282Z", "startedAt": "2021-09-08T08:30:30.553012Z", "finishedAt": "2021-09-08T08:31:12.304168Z"}]})
); );
// finally we're just going to check that we can still get a few documents by id // finally we're just going to check that we can still get a few documents by id
@ -134,7 +134,7 @@ async fn import_dump_v2_movie_with_settings() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!( assert_eq!(
tasks, tasks,
json!({ "results": [{ "uid": 1, "indexUid": "indexUID", "status": "succeeded", "type": "settingsUpdate", "details": { "displayedAttributes": ["title", "genres", "overview", "poster", "release_date"], "searchableAttributes": ["title", "overview"], "filterableAttributes": ["genres"], "stopWords": ["of", "the"] }, "duration": "PT37.488777S", "enqueuedAt": "2021-09-08T08:24:02.323444Z", "startedAt": "2021-09-08T08:24:02.324145Z", "finishedAt": "2021-09-08T08:24:39.812922Z" }, { "uid": 0, "indexUid": "indexUID", "status": "succeeded", "type": "documentAddition", "details": { "receivedDocuments": 0, "indexedDocuments": 31944 }, "duration": "PT39.941318S", "enqueuedAt": "2021-09-08T08:21:14.742672Z", "startedAt": "2021-09-08T08:21:14.750166Z", "finishedAt": "2021-09-08T08:21:54.691484Z" }]}) json!({ "results": [{ "uid": 1, "indexUid": "indexUID", "status": "succeeded", "type": "settingsUpdate", "details": { "displayedAttributes": ["title", "genres", "overview", "poster", "release_date"], "searchableAttributes": ["title", "overview"], "filterableAttributes": ["genres"], "stopWords": ["of", "the"] }, "duration": "PT37.488777S", "enqueuedAt": "2021-09-08T08:24:02.323444Z", "startedAt": "2021-09-08T08:24:02.324145Z", "finishedAt": "2021-09-08T08:24:39.812922Z" }, { "uid": 0, "indexUid": "indexUID", "status": "succeeded", "type": "documentAdditionOrUpdate", "details": { "receivedDocuments": 0, "indexedDocuments": 31944 }, "duration": "PT39.941318S", "enqueuedAt": "2021-09-08T08:21:14.742672Z", "startedAt": "2021-09-08T08:21:14.750166Z", "finishedAt": "2021-09-08T08:21:54.691484Z" }]})
); );
// finally we're just going to check that we can still get a few documents by id // finally we're just going to check that we can still get a few documents by id
@ -199,7 +199,7 @@ async fn import_dump_v2_rubygems_with_settings() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!( assert_eq!(
tasks["results"][0], tasks["results"][0],
json!({"uid": 92, "indexUid": "rubygems", "status": "succeeded", "type": "documentAddition", "details": {"receivedDocuments": 0, "indexedDocuments": 1042}, "duration": "PT14.034672S", "enqueuedAt": "2021-09-08T08:40:31.390775Z", "startedAt": "2021-09-08T08:51:39.060642Z", "finishedAt": "2021-09-08T08:51:53.095314Z"}) json!({"uid": 92, "indexUid": "rubygems", "status": "succeeded", "type": "documentAdditionOrUpdate", "details": {"receivedDocuments": 0, "indexedDocuments": 1042}, "duration": "PT14.034672S", "enqueuedAt": "2021-09-08T08:40:31.390775Z", "startedAt": "2021-09-08T08:51:39.060642Z", "finishedAt": "2021-09-08T08:51:53.095314Z"})
); );
assert_eq!( assert_eq!(
tasks["results"][92], tasks["results"][92],
@ -268,7 +268,7 @@ async fn import_dump_v3_movie_raw() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!( assert_eq!(
tasks, tasks,
json!({ "results": [{"uid": 0, "indexUid": "indexUID", "status": "succeeded", "type": "documentAddition", "details": { "receivedDocuments": 0, "indexedDocuments": 31944 }, "duration": "PT41.751156S", "enqueuedAt": "2021-09-08T08:30:30.550282Z", "startedAt": "2021-09-08T08:30:30.553012Z", "finishedAt": "2021-09-08T08:31:12.304168Z"}]}) json!({ "results": [{"uid": 0, "indexUid": "indexUID", "status": "succeeded", "type": "documentAdditionOrUpdate", "details": { "receivedDocuments": 0, "indexedDocuments": 31944 }, "duration": "PT41.751156S", "enqueuedAt": "2021-09-08T08:30:30.550282Z", "startedAt": "2021-09-08T08:30:30.553012Z", "finishedAt": "2021-09-08T08:31:12.304168Z"}]})
); );
// finally we're just going to check that we can still get a few documents by id // finally we're just going to check that we can still get a few documents by id
@ -333,7 +333,7 @@ async fn import_dump_v3_movie_with_settings() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!( assert_eq!(
tasks, tasks,
json!({ "results": [{ "uid": 1, "indexUid": "indexUID", "status": "succeeded", "type": "settingsUpdate", "details": { "displayedAttributes": ["title", "genres", "overview", "poster", "release_date"], "searchableAttributes": ["title", "overview"], "filterableAttributes": ["genres"], "stopWords": ["of", "the"] }, "duration": "PT37.488777S", "enqueuedAt": "2021-09-08T08:24:02.323444Z", "startedAt": "2021-09-08T08:24:02.324145Z", "finishedAt": "2021-09-08T08:24:39.812922Z" }, { "uid": 0, "indexUid": "indexUID", "status": "succeeded", "type": "documentAddition", "details": { "receivedDocuments": 0, "indexedDocuments": 31944 }, "duration": "PT39.941318S", "enqueuedAt": "2021-09-08T08:21:14.742672Z", "startedAt": "2021-09-08T08:21:14.750166Z", "finishedAt": "2021-09-08T08:21:54.691484Z" }]}) json!({ "results": [{ "uid": 1, "indexUid": "indexUID", "status": "succeeded", "type": "settingsUpdate", "details": { "displayedAttributes": ["title", "genres", "overview", "poster", "release_date"], "searchableAttributes": ["title", "overview"], "filterableAttributes": ["genres"], "stopWords": ["of", "the"] }, "duration": "PT37.488777S", "enqueuedAt": "2021-09-08T08:24:02.323444Z", "startedAt": "2021-09-08T08:24:02.324145Z", "finishedAt": "2021-09-08T08:24:39.812922Z" }, { "uid": 0, "indexUid": "indexUID", "status": "succeeded", "type": "documentAdditionOrUpdate", "details": { "receivedDocuments": 0, "indexedDocuments": 31944 }, "duration": "PT39.941318S", "enqueuedAt": "2021-09-08T08:21:14.742672Z", "startedAt": "2021-09-08T08:21:14.750166Z", "finishedAt": "2021-09-08T08:21:54.691484Z" }]})
); );
// finally we're just going to check that we can still get a few documents by id // finally we're just going to check that we can still get a few documents by id
@ -398,7 +398,7 @@ async fn import_dump_v3_rubygems_with_settings() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!( assert_eq!(
tasks["results"][0], tasks["results"][0],
json!({"uid": 92, "indexUid": "rubygems", "status": "succeeded", "type": "documentAddition", "details": {"receivedDocuments": 0, "indexedDocuments": 1042}, "duration": "PT14.034672S", "enqueuedAt": "2021-09-08T08:40:31.390775Z", "startedAt": "2021-09-08T08:51:39.060642Z", "finishedAt": "2021-09-08T08:51:53.095314Z"}) json!({"uid": 92, "indexUid": "rubygems", "status": "succeeded", "type": "documentAdditionOrUpdate", "details": {"receivedDocuments": 0, "indexedDocuments": 1042}, "duration": "PT14.034672S", "enqueuedAt": "2021-09-08T08:40:31.390775Z", "startedAt": "2021-09-08T08:51:39.060642Z", "finishedAt": "2021-09-08T08:51:53.095314Z"})
); );
assert_eq!( assert_eq!(
tasks["results"][92], tasks["results"][92],
@ -467,7 +467,7 @@ async fn import_dump_v4_movie_raw() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!( assert_eq!(
tasks, tasks,
json!({ "results": [{"uid": 0, "indexUid": "indexUID", "status": "succeeded", "type": "documentAddition", "details": { "receivedDocuments": 0, "indexedDocuments": 31944 }, "duration": "PT41.751156S", "enqueuedAt": "2021-09-08T08:30:30.550282Z", "startedAt": "2021-09-08T08:30:30.553012Z", "finishedAt": "2021-09-08T08:31:12.304168Z"}]}) json!({ "results": [{"uid": 0, "indexUid": "indexUID", "status": "succeeded", "type": "documentAdditionOrUpdate", "details": { "receivedDocuments": 0, "indexedDocuments": 31944 }, "duration": "PT41.751156S", "enqueuedAt": "2021-09-08T08:30:30.550282Z", "startedAt": "2021-09-08T08:30:30.553012Z", "finishedAt": "2021-09-08T08:31:12.304168Z"}]})
); );
// finally we're just going to check that we can still get a few documents by id // finally we're just going to check that we can still get a few documents by id
@ -532,7 +532,7 @@ async fn import_dump_v4_movie_with_settings() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!( assert_eq!(
tasks, tasks,
json!({ "results": [{ "uid": 1, "indexUid": "indexUID", "status": "succeeded", "type": "settingsUpdate", "details": { "displayedAttributes": ["title", "genres", "overview", "poster", "release_date"], "searchableAttributes": ["title", "overview"], "filterableAttributes": ["genres"], "stopWords": ["of", "the"] }, "duration": "PT37.488777S", "enqueuedAt": "2021-09-08T08:24:02.323444Z", "startedAt": "2021-09-08T08:24:02.324145Z", "finishedAt": "2021-09-08T08:24:39.812922Z" }, { "uid": 0, "indexUid": "indexUID", "status": "succeeded", "type": "documentAddition", "details": { "receivedDocuments": 0, "indexedDocuments": 31944 }, "duration": "PT39.941318S", "enqueuedAt": "2021-09-08T08:21:14.742672Z", "startedAt": "2021-09-08T08:21:14.750166Z", "finishedAt": "2021-09-08T08:21:54.691484Z" }]}) json!({ "results": [{ "uid": 1, "indexUid": "indexUID", "status": "succeeded", "type": "settingsUpdate", "details": { "displayedAttributes": ["title", "genres", "overview", "poster", "release_date"], "searchableAttributes": ["title", "overview"], "filterableAttributes": ["genres"], "stopWords": ["of", "the"] }, "duration": "PT37.488777S", "enqueuedAt": "2021-09-08T08:24:02.323444Z", "startedAt": "2021-09-08T08:24:02.324145Z", "finishedAt": "2021-09-08T08:24:39.812922Z" }, { "uid": 0, "indexUid": "indexUID", "status": "succeeded", "type": "documentAdditionOrUpdate", "details": { "receivedDocuments": 0, "indexedDocuments": 31944 }, "duration": "PT39.941318S", "enqueuedAt": "2021-09-08T08:21:14.742672Z", "startedAt": "2021-09-08T08:21:14.750166Z", "finishedAt": "2021-09-08T08:21:54.691484Z" }]})
); );
// finally we're just going to check that we can still get a few documents by id // finally we're just going to check that we can still get a few documents by id
@ -597,7 +597,7 @@ async fn import_dump_v4_rubygems_with_settings() {
assert_eq!(code, 200); assert_eq!(code, 200);
assert_eq!( assert_eq!(
tasks["results"][0], tasks["results"][0],
json!({ "uid": 92, "indexUid": "rubygems", "status": "succeeded", "type": "documentAddition", "details": {"receivedDocuments": 0, "indexedDocuments": 1042}, "duration": "PT14.034672S", "enqueuedAt": "2021-09-08T08:40:31.390775Z", "startedAt": "2021-09-08T08:51:39.060642Z", "finishedAt": "2021-09-08T08:51:53.095314Z"}) json!({ "uid": 92, "indexUid": "rubygems", "status": "succeeded", "type": "documentAdditionOrUpdate", "details": {"receivedDocuments": 0, "indexedDocuments": 1042}, "duration": "PT14.034672S", "enqueuedAt": "2021-09-08T08:40:31.390775Z", "startedAt": "2021-09-08T08:51:39.060642Z", "finishedAt": "2021-09-08T08:51:53.095314Z"})
); );
assert_eq!( assert_eq!(
tasks["results"][92], tasks["results"][92],

View File

@ -76,9 +76,10 @@ async fn list_tasks_status_filtered() {
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!(response["results"].as_array().unwrap().len(), 1); assert_eq!(response["results"].as_array().unwrap().len(), 1);
let (response, code) = index.filtered_tasks(&[], &["processing"]).await; // We can't be sure that the update isn't already processed so we can't test this
assert_eq!(code, 200, "{}", response); // let (response, code) = index.filtered_tasks(&[], &["processing"]).await;
assert_eq!(response["results"].as_array().unwrap().len(), 1); // assert_eq!(code, 200, "{}", response);
// assert_eq!(response["results"].as_array().unwrap().len(), 1);
index.wait_task(1).await; index.wait_task(1).await;
@ -105,7 +106,7 @@ async fn list_tasks_type_filtered() {
assert_eq!(response["results"].as_array().unwrap().len(), 1); assert_eq!(response["results"].as_array().unwrap().len(), 1);
let (response, code) = index let (response, code) = index
.filtered_tasks(&["indexCreation", "documentAddition"], &[]) .filtered_tasks(&["indexCreation", "documentAdditionOrUpdate"], &[])
.await; .await;
assert_eq!(code, 200, "{}", response); assert_eq!(code, 200, "{}", response);
assert_eq!(response["results"].as_array().unwrap().len(), 2); assert_eq!(response["results"].as_array().unwrap().len(), 2);
@ -130,7 +131,7 @@ async fn list_tasks_status_and_type_filtered() {
let (response, code) = index let (response, code) = index
.filtered_tasks( .filtered_tasks(
&["indexCreation", "documentAddition"], &["indexCreation", "documentAdditionOrUpdate"],
&["succeeded", "processing"], &["succeeded", "processing"],
) )
.await; .await;
@ -166,16 +167,16 @@ async fn test_summarized_task_view() {
assert_valid_summarized_task!(response, "settingsUpdate", "test"); assert_valid_summarized_task!(response, "settingsUpdate", "test");
let (response, _) = index.update_documents(json!([{"id": 1}]), None).await; let (response, _) = index.update_documents(json!([{"id": 1}]), None).await;
assert_valid_summarized_task!(response, "documentPartial", "test"); assert_valid_summarized_task!(response, "documentAdditionOrUpdate", "test");
let (response, _) = index.add_documents(json!([{"id": 1}]), None).await; let (response, _) = index.add_documents(json!([{"id": 1}]), None).await;
assert_valid_summarized_task!(response, "documentAddition", "test"); assert_valid_summarized_task!(response, "documentAdditionOrUpdate", "test");
let (response, _) = index.delete_document(1).await; let (response, _) = index.delete_document(1).await;
assert_valid_summarized_task!(response, "documentDeletion", "test"); assert_valid_summarized_task!(response, "documentDeletion", "test");
let (response, _) = index.clear_all_documents().await; let (response, _) = index.clear_all_documents().await;
assert_valid_summarized_task!(response, "clearAll", "test"); assert_valid_summarized_task!(response, "documentDeletion", "test");
let (response, _) = index.delete().await; let (response, _) = index.delete().await;
assert_valid_summarized_task!(response, "indexDeletion", "test"); assert_valid_summarized_task!(response, "indexDeletion", "test");