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

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