mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-11-25 22:34:28 +01:00
Update the canceledBy and finishedAt fields
This commit is contained in:
parent
725158b454
commit
290945e258
@ -62,6 +62,9 @@ pub struct TaskDump {
|
||||
#[serde(rename = "type")]
|
||||
pub kind: KindDump,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub canceled_by: Option<TaskId>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub details: Option<Details>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -136,6 +139,7 @@ impl From<Task> for TaskDump {
|
||||
index_uid: task.index_uid().map(|uid| uid.to_string()),
|
||||
status: task.status,
|
||||
kind: task.kind.into(),
|
||||
canceled_by: task.canceled_by,
|
||||
details: task.details,
|
||||
error: task.error,
|
||||
enqueued_at: task.enqueued_at,
|
||||
@ -289,6 +293,7 @@ pub(crate) mod test {
|
||||
primary_key: Some(S("bone")),
|
||||
documents_count: 12,
|
||||
},
|
||||
canceled_by: None,
|
||||
details: Some(Details::DocumentAddition {
|
||||
received_documents: 12,
|
||||
indexed_documents: Some(10),
|
||||
@ -311,6 +316,7 @@ pub(crate) mod test {
|
||||
primary_key: None,
|
||||
documents_count: 2,
|
||||
},
|
||||
canceled_by: None,
|
||||
details: Some(Details::DocumentAddition {
|
||||
received_documents: 2,
|
||||
indexed_documents: None,
|
||||
@ -337,6 +343,7 @@ pub(crate) mod test {
|
||||
index_uid: Some(S("catto")),
|
||||
status: Status::Enqueued,
|
||||
kind: KindDump::IndexDeletion,
|
||||
canceled_by: None,
|
||||
details: None,
|
||||
error: None,
|
||||
enqueued_at: datetime!(2022-11-15 0:00 UTC),
|
||||
|
@ -125,6 +125,7 @@ impl CompatV5ToV6 {
|
||||
instance_uid: instance_uid.clone(),
|
||||
},
|
||||
},
|
||||
canceled_by: None,
|
||||
details: task_view.details.map(|details| match details {
|
||||
v5::Details::DocumentAddition {
|
||||
received_documents,
|
||||
|
@ -468,7 +468,8 @@ impl IndexScheduler {
|
||||
};
|
||||
|
||||
let mut wtxn = self.env.write_txn()?;
|
||||
let nbr_canceled_tasks = self.cancel_matched_tasks(&mut wtxn, matched_tasks)?;
|
||||
let canceled_tasks_count =
|
||||
self.cancel_matched_tasks(&mut wtxn, task.uid, matched_tasks)?;
|
||||
|
||||
task.status = Status::Succeeded;
|
||||
match &mut task.details {
|
||||
@ -477,7 +478,7 @@ impl IndexScheduler {
|
||||
canceled_tasks,
|
||||
original_query: _,
|
||||
}) => {
|
||||
*canceled_tasks = Some(nbr_canceled_tasks);
|
||||
*canceled_tasks = Some(canceled_tasks_count);
|
||||
}
|
||||
_ => unreachable!(),
|
||||
}
|
||||
@ -1029,20 +1030,25 @@ impl IndexScheduler {
|
||||
fn cancel_matched_tasks(
|
||||
&self,
|
||||
wtxn: &mut RwTxn,
|
||||
cancel_task_id: TaskId,
|
||||
matched_tasks: &RoaringBitmap,
|
||||
) -> Result<usize> {
|
||||
let now = OffsetDateTime::now_utc();
|
||||
|
||||
// 1. Remove from this list the tasks that we are not allowed to cancel
|
||||
// Notice that only the _enqueued_ ones are cancelable and we should
|
||||
// have already aborted the indexation of the _processing_ ones
|
||||
let cancelable_tasks = self.get_status(&wtxn, Status::Enqueued)?;
|
||||
let cancelable_tasks = self.get_status(wtxn, Status::Enqueued)?;
|
||||
let tasks_to_cancel = cancelable_tasks & matched_tasks;
|
||||
|
||||
// 2. We now have a list of tasks to cancel, cancel them
|
||||
self.update_status(wtxn, Status::Enqueued, |bitmap| *bitmap -= &tasks_to_cancel)?;
|
||||
self.update_status(wtxn, Status::Canceled, |bitmap| *bitmap |= &tasks_to_cancel)?;
|
||||
|
||||
// TODO update the content of the tasks i.e. canceled_by and finished_at
|
||||
// TODO delete the content uuid of the tasks
|
||||
for mut task in self.get_existing_tasks(wtxn, tasks_to_cancel.iter())? {
|
||||
// TODO delete the content uuid of the task
|
||||
task.status = Status::Canceled;
|
||||
task.canceled_by = Some(cancel_task_id);
|
||||
task.finished_at = Some(now);
|
||||
self.update_task(wtxn, &task)?;
|
||||
}
|
||||
|
||||
Ok(tasks_to_cancel.len() as usize)
|
||||
}
|
||||
|
@ -397,6 +397,7 @@ impl IndexScheduler {
|
||||
started_at: None,
|
||||
finished_at: None,
|
||||
error: None,
|
||||
canceled_by: None,
|
||||
details: kind.default_details(),
|
||||
status: Status::Enqueued,
|
||||
kind: kind.clone(),
|
||||
@ -478,6 +479,7 @@ impl IndexScheduler {
|
||||
started_at: task.started_at,
|
||||
finished_at: task.finished_at,
|
||||
error: task.error,
|
||||
canceled_by: task.canceled_by,
|
||||
details: task.details,
|
||||
status: task.status,
|
||||
kind: match task.kind {
|
||||
|
@ -38,6 +38,9 @@ pub struct TaskView {
|
||||
#[serde(rename = "type")]
|
||||
pub kind: Kind,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub canceled_by: Option<TaskId>,
|
||||
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub details: Option<DetailsView>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@ -74,6 +77,7 @@ impl TaskView {
|
||||
.and_then(|vec| vec.first().map(|i| i.to_string())),
|
||||
status: task.status,
|
||||
kind: task.kind.as_kind(),
|
||||
canceled_by: task.canceled_by,
|
||||
details: task.details.clone().map(DetailsView::from),
|
||||
error: task.error.clone(),
|
||||
duration: task
|
||||
|
@ -30,6 +30,7 @@ pub struct Task {
|
||||
pub finished_at: Option<OffsetDateTime>,
|
||||
|
||||
pub error: Option<ResponseError>,
|
||||
pub canceled_by: Option<TaskId>,
|
||||
pub details: Option<Details>,
|
||||
|
||||
pub status: Status,
|
||||
|
Loading…
Reference in New Issue
Block a user