Introduce the task cancelation task type

This commit is contained in:
Kerollmops 2022-10-17 17:19:17 +02:00 committed by Clément Renault
parent f177c97671
commit 1ca9a67c49
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
7 changed files with 131 additions and 41 deletions

View file

@ -44,7 +44,7 @@ impl Task {
match &self.kind {
DumpExport { .. }
| Snapshot
| CancelTask { .. }
| TaskCancelation { .. }
| TaskDeletion { .. }
| IndexSwap { .. } => None,
DocumentImport { index_uid, .. }
@ -62,7 +62,7 @@ impl Task {
use KindWithContent::*;
match &self.kind {
DumpExport { .. } | Snapshot | CancelTask { .. } | TaskDeletion { .. } => None,
DumpExport { .. } | Snapshot | TaskCancelation { .. } | TaskDeletion { .. } => None,
DocumentImport { index_uid, .. }
| DocumentDeletion { index_uid, .. }
| DocumentClear { index_uid }
@ -87,7 +87,7 @@ impl Task {
| KindWithContent::IndexCreation { .. }
| KindWithContent::IndexUpdate { .. }
| KindWithContent::IndexSwap { .. }
| KindWithContent::CancelTask { .. }
| KindWithContent::TaskCancelation { .. }
| KindWithContent::TaskDeletion { .. }
| KindWithContent::DumpExport { .. }
| KindWithContent::Snapshot => None,
@ -95,7 +95,7 @@ impl Task {
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum KindWithContent {
DocumentImport {
@ -134,7 +134,8 @@ pub enum KindWithContent {
lhs: String,
rhs: String,
},
CancelTask {
TaskCancelation {
query: String,
tasks: Vec<TaskId>,
},
TaskDeletion {
@ -160,7 +161,7 @@ impl KindWithContent {
KindWithContent::IndexDeletion { .. } => Kind::IndexDeletion,
KindWithContent::IndexUpdate { .. } => Kind::IndexUpdate,
KindWithContent::IndexSwap { .. } => Kind::IndexSwap,
KindWithContent::CancelTask { .. } => Kind::CancelTask,
KindWithContent::TaskCancelation { .. } => Kind::TaskCancelation,
KindWithContent::TaskDeletion { .. } => Kind::TaskDeletion,
KindWithContent::DumpExport { .. } => Kind::DumpExport,
KindWithContent::Snapshot => Kind::Snapshot,
@ -171,7 +172,7 @@ impl KindWithContent {
use KindWithContent::*;
match self {
DumpExport { .. } | Snapshot | CancelTask { .. } | TaskDeletion { .. } => None,
DumpExport { .. } | Snapshot | TaskCancelation { .. } | TaskDeletion { .. } => None,
DocumentImport { index_uid, .. }
| DocumentDeletion { index_uid, .. }
| DocumentClear { index_uid }
@ -214,7 +215,7 @@ impl KindWithContent {
KindWithContent::IndexSwap { .. } => {
todo!()
}
KindWithContent::CancelTask { .. } => {
KindWithContent::TaskCancelation { .. } => {
None // TODO: check correctness of this return value
}
KindWithContent::TaskDeletion { query, tasks } => Some(Details::TaskDeletion {
@ -250,7 +251,7 @@ impl From<&KindWithContent> for Option<Details> {
primary_key: primary_key.clone(),
}),
KindWithContent::IndexSwap { .. } => None,
KindWithContent::CancelTask { .. } => None,
KindWithContent::TaskCancelation { .. } => None,
KindWithContent::TaskDeletion { query, tasks } => Some(Details::TaskDeletion {
matched_tasks: tasks.len(),
deleted_tasks: None,
@ -327,7 +328,7 @@ pub enum Kind {
IndexDeletion,
IndexUpdate,
IndexSwap,
CancelTask,
TaskCancelation,
TaskDeletion,
DumpExport,
Snapshot,
@ -349,6 +350,10 @@ impl FromStr for Kind {
Ok(Kind::DocumentDeletion)
} else if kind.eq_ignore_ascii_case("settingsUpdate") {
Ok(Kind::Settings)
} else if kind.eq_ignore_ascii_case("TaskCancelation") {
Ok(Kind::TaskCancelation)
} else if kind.eq_ignore_ascii_case("TaskDeletion") {
Ok(Kind::TaskDeletion)
} else if kind.eq_ignore_ascii_case("dumpCreation") {
Ok(Kind::DumpExport)
} else {
@ -392,6 +397,11 @@ pub enum Details {
ClearAll {
deleted_documents: Option<u64>,
},
TaskCancelation {
matched_tasks: usize,
canceled_tasks: Option<usize>,
original_query: String,
},
TaskDeletion {
matched_tasks: u64,
deleted_tasks: Option<usize>,