mirror of
https://github.com/meilisearch/meilisearch.git
synced 2025-10-26 05:26:27 +00:00
Progress, in the task queue
This commit is contained in:
@@ -4,7 +4,9 @@ use time::{Duration, OffsetDateTime};
|
||||
|
||||
use crate::error::ResponseError;
|
||||
use crate::settings::{Settings, Unchecked};
|
||||
use crate::tasks::{serialize_duration, Details, IndexSwap, Kind, Status, Task, TaskId};
|
||||
use crate::tasks::{
|
||||
serialize_duration, Details, IndexSwap, Kind, Status, Task, TaskId, TaskProgress,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
@@ -27,6 +29,8 @@ pub struct TaskView {
|
||||
pub started_at: Option<OffsetDateTime>,
|
||||
#[serde(with = "time::serde::rfc3339::option", default)]
|
||||
pub finished_at: Option<OffsetDateTime>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub progress: Option<TaskProgress>,
|
||||
}
|
||||
|
||||
impl TaskView {
|
||||
@@ -43,6 +47,7 @@ impl TaskView {
|
||||
enqueued_at: task.enqueued_at,
|
||||
started_at: task.started_at,
|
||||
finished_at: task.finished_at,
|
||||
progress: task.progress.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ use std::fmt::{Display, Write};
|
||||
use std::str::FromStr;
|
||||
|
||||
use enum_iterator::Sequence;
|
||||
use milli::update::new::indexer::document_changes::Progress;
|
||||
use milli::update::IndexDocumentsMethod;
|
||||
use milli::Object;
|
||||
use roaring::RoaringBitmap;
|
||||
@@ -30,6 +31,8 @@ pub struct Task {
|
||||
#[serde(with = "time::serde::rfc3339::option")]
|
||||
pub finished_at: Option<OffsetDateTime>,
|
||||
|
||||
pub progress: Option<TaskProgress>,
|
||||
|
||||
pub error: Option<ResponseError>,
|
||||
pub canceled_by: Option<TaskId>,
|
||||
pub details: Option<Details>,
|
||||
@@ -38,6 +41,59 @@ pub struct Task {
|
||||
pub kind: KindWithContent,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TaskProgress {
|
||||
pub current_step: String,
|
||||
pub finished_steps: u16,
|
||||
pub total_steps: u16,
|
||||
pub finished_documents: Option<u32>,
|
||||
pub total_documents: Option<u32>,
|
||||
}
|
||||
|
||||
impl Default for TaskProgress {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl TaskProgress {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
current_step: String::new(),
|
||||
finished_steps: 0,
|
||||
total_steps: 1,
|
||||
finished_documents: None,
|
||||
total_documents: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update(&mut self, progress: Progress) {
|
||||
if self.current_step != progress.step_name {
|
||||
self.current_step.clear();
|
||||
self.current_step.push_str(progress.step_name);
|
||||
}
|
||||
self.total_steps = progress.total_steps;
|
||||
if self.finished_steps > progress.finished_steps {
|
||||
return;
|
||||
}
|
||||
if self.finished_steps < progress.finished_steps {
|
||||
self.finished_documents = None;
|
||||
self.total_documents = None;
|
||||
}
|
||||
self.finished_steps = progress.finished_steps;
|
||||
if let Some((finished_documents, total_documents)) = progress.finished_total_documents {
|
||||
if let Some(task_finished_documents) = self.finished_documents {
|
||||
if task_finished_documents > finished_documents {
|
||||
return;
|
||||
}
|
||||
}
|
||||
self.finished_documents = Some(finished_documents);
|
||||
self.total_documents = Some(total_documents);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Task {
|
||||
pub fn index_uid(&self) -> Option<&str> {
|
||||
use KindWithContent::*;
|
||||
|
||||
Reference in New Issue
Block a user