Use the new indexing progress events in the http server

This commit is contained in:
Clément Renault 2020-11-11 13:14:16 +01:00
parent ea43080548
commit a71a96894d
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
2 changed files with 39 additions and 11 deletions

View File

@ -54,13 +54,22 @@ $(window).on('load', function () {
const content = $(`#${id} .updateStatus.content`); const content = $(`#${id} .updateStatus.content`);
let html; let html;
let { type, processed_number_of_documents, total_number_of_documents } = status.meta;
if (type === 'DocumentsAddition' && processed_number_of_documents && total_number_of_documents) { let { type, step, total_steps, current, total } = status.meta;
let progress = Math.round(processed_number_of_documents / total_number_of_documents * 100);
if (type === 'DocumentsAddition') {
// If the total is null or undefined then the progress results is infinity.
let progress = Math.round(current / total * 100);
// We must divide the progress by the total number of indexing steps.
progress = progress / total_steps;
// And mark the previous steps as processed.
progress = progress + (step * 100 / total_steps);
// Generate the appropriate html bulma progress bar.
html = `<progress class="progress" title="${progress}%" value="${progress}" max="100"></progress>`; html = `<progress class="progress" title="${progress}%" value="${progress}" max="100"></progress>`;
} else { } else {
html = `<progress class="progress" max="100"></progress>`; html = `<progress class="progress" max="100"></progress>`;
} }
content.html(html); content.html(html);
} }

View File

@ -26,6 +26,7 @@ use warp::filters::ws::Message;
use warp::{Filter, http::Response}; use warp::{Filter, http::Response};
use milli::tokenizer::{simple_tokenizer, TokenType}; use milli::tokenizer::{simple_tokenizer, TokenType};
use milli::update::UpdateIndexingStep::*;
use milli::update::{UpdateBuilder, IndexDocumentsMethod, UpdateFormat}; use milli::update::{UpdateBuilder, IndexDocumentsMethod, UpdateFormat};
use milli::{obkv_to_json, Index, UpdateStore, SearchResult}; use milli::{obkv_to_json, Index, UpdateStore, SearchResult};
@ -201,8 +202,10 @@ enum UpdateMeta {
#[serde(tag = "type")] #[serde(tag = "type")]
enum UpdateMetaProgress { enum UpdateMetaProgress {
DocumentsAddition { DocumentsAddition {
processed_number_of_documents: usize, step: usize,
total_number_of_documents: Option<usize>, total_steps: usize,
current: usize,
total: Option<usize>,
}, },
} }
@ -310,12 +313,20 @@ async fn main() -> anyhow::Result<()> {
Box::new(content) as Box<dyn io::Read> Box::new(content) as Box<dyn io::Read>
}; };
let result = builder.execute(reader, |count, total| { let result = builder.execute(reader, |indexing_step| {
let (current, total) = match indexing_step {
TransformFromUserIntoGenericFormat { documents_seen } => (documents_seen, None),
ComputeIdsAndMergeDocuments { documents_seen, total_documents } => (documents_seen, Some(total_documents)),
IndexDocuments { documents_seen, total_documents } => (documents_seen, Some(total_documents)),
MergeDataIntoFinalDatabase { databases_seen, total_databases } => (databases_seen, Some(total_databases)),
};
let _ = update_status_sender_cloned.send(UpdateStatus::Progressing { let _ = update_status_sender_cloned.send(UpdateStatus::Progressing {
update_id, update_id,
meta: UpdateMetaProgress::DocumentsAddition { meta: UpdateMetaProgress::DocumentsAddition {
processed_number_of_documents: count, step: indexing_step.step(),
total_number_of_documents: Some(total), total_steps: indexing_step.number_of_steps(),
current,
total,
} }
}); });
}); });
@ -356,12 +367,20 @@ async fn main() -> anyhow::Result<()> {
} }
} }
let result = builder.execute(|count, total| { let result = builder.execute(|indexing_step| {
let (current, total) = match indexing_step {
TransformFromUserIntoGenericFormat { documents_seen } => (documents_seen, None),
ComputeIdsAndMergeDocuments { documents_seen, total_documents } => (documents_seen, Some(total_documents)),
IndexDocuments { documents_seen, total_documents } => (documents_seen, Some(total_documents)),
MergeDataIntoFinalDatabase { databases_seen, total_databases } => (databases_seen, Some(total_databases)),
};
let _ = update_status_sender_cloned.send(UpdateStatus::Progressing { let _ = update_status_sender_cloned.send(UpdateStatus::Progressing {
update_id, update_id,
meta: UpdateMetaProgress::DocumentsAddition { meta: UpdateMetaProgress::DocumentsAddition {
processed_number_of_documents: count, step: indexing_step.step(),
total_number_of_documents: Some(total), total_steps: indexing_step.number_of_steps(),
current,
total,
} }
}); });
}); });