mirror of
https://github.com/meilisearch/MeiliSearch
synced 2025-07-03 11:57:07 +02:00
Merge #2410
2410: Make dump a task r=Kerollmops a=MarinPostma This PR transforms the dump task into a proper task. The `GET /dumps/:dump_uid` is removed. Some changes were made to make this work, and a bit a refactoring was necessary. - The `dump_actor` module has been renamed do `dumps` and moved to the root - There isn't a `DumpActor` anymore, and the dump process is handled by the `DumpHandler`. - The `TaskPerformer` is renamed to `BatchHandler` - The `BatchHandler` trait no longer has a `perform_job` method, but instead has a `accept` method returning whether a handler can proccess a batch - The scheduler now accept a list of `BatchHandler`, and iterates trhough them until it finds one to accept the current batch. - `Job` doesn't exist anymore, and everything in now inside of the `BatchContent` enum. - The `Vec<TaskId>` from `Batch` is replaced with a `BatchContent` enum which hints at the content. - The Scheduler is slightly modified to accept batch, and prioritize them before regular tasks. - The `TaskList` are not identified by a `String` representing the index uid anymore, but by a `TaskListIdentifier` which also works for dumps which are not targeting any specific indexes. - The `GET /dump/:dump_id` no longer exists - `DumpActorError` is renamed to `DumpError` close #2410 Co-authored-by: ad hoc <postma.marin@protonmail.com>
This commit is contained in:
commit
3441cc6c36
38 changed files with 1398 additions and 1292 deletions
|
@ -2,18 +2,15 @@ use actix_web::{web, HttpRequest, HttpResponse};
|
|||
use log::debug;
|
||||
use meilisearch_error::ResponseError;
|
||||
use meilisearch_lib::MeiliSearch;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::analytics::Analytics;
|
||||
use crate::extractors::authentication::{policies::*, GuardedData};
|
||||
use crate::extractors::sequential_extractor::SeqHandler;
|
||||
use crate::task::SummarizedTaskView;
|
||||
|
||||
pub fn configure(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(web::resource("").route(web::post().to(SeqHandler(create_dump))))
|
||||
.service(
|
||||
web::resource("/{dump_uid}/status").route(web::get().to(SeqHandler(get_dump_status))),
|
||||
);
|
||||
cfg.service(web::resource("").route(web::post().to(SeqHandler(create_dump))));
|
||||
}
|
||||
|
||||
pub async fn create_dump(
|
||||
|
@ -23,29 +20,8 @@ pub async fn create_dump(
|
|||
) -> Result<HttpResponse, ResponseError> {
|
||||
analytics.publish("Dump Created".to_string(), json!({}), Some(&req));
|
||||
|
||||
let res = meilisearch.create_dump().await?;
|
||||
let res: SummarizedTaskView = meilisearch.register_dump_task().await?.into();
|
||||
|
||||
debug!("returns: {:?}", res);
|
||||
Ok(HttpResponse::Accepted().json(res))
|
||||
}
|
||||
|
||||
#[derive(Debug, Serialize)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
struct DumpStatusResponse {
|
||||
status: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct DumpParam {
|
||||
dump_uid: String,
|
||||
}
|
||||
|
||||
async fn get_dump_status(
|
||||
meilisearch: GuardedData<ActionPolicy<{ actions::DUMPS_GET }>, MeiliSearch>,
|
||||
path: web::Path<DumpParam>,
|
||||
) -> Result<HttpResponse, ResponseError> {
|
||||
let res = meilisearch.dump_info(path.dump_uid.clone()).await?;
|
||||
|
||||
debug!("returns: {:?}", res);
|
||||
Ok(HttpResponse::Ok().json(res))
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ enum TaskType {
|
|||
DocumentDeletion,
|
||||
SettingsUpdate,
|
||||
ClearAll,
|
||||
DumpCreation,
|
||||
}
|
||||
|
||||
impl From<TaskContent> for TaskType {
|
||||
|
@ -43,6 +44,7 @@ impl From<TaskContent> for TaskType {
|
|||
TaskContent::IndexDeletion => TaskType::IndexDeletion,
|
||||
TaskContent::IndexCreation { .. } => TaskType::IndexCreation,
|
||||
TaskContent::IndexUpdate { .. } => TaskType::IndexUpdate,
|
||||
TaskContent::Dump { .. } => TaskType::DumpCreation,
|
||||
_ => unreachable!("unexpected task type"),
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +82,8 @@ enum TaskDetails {
|
|||
},
|
||||
#[serde(rename_all = "camelCase")]
|
||||
ClearAll { deleted_documents: Option<u64> },
|
||||
#[serde(rename_all = "camelCase")]
|
||||
Dump { dump_uid: String },
|
||||
}
|
||||
|
||||
/// Serialize a `time::Duration` as a best effort ISO 8601 while waiting for
|
||||
|
@ -137,7 +141,7 @@ fn serialize_duration<S: Serializer>(
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TaskView {
|
||||
uid: TaskId,
|
||||
index_uid: String,
|
||||
index_uid: Option<String>,
|
||||
status: TaskStatus,
|
||||
#[serde(rename = "type")]
|
||||
task_type: TaskType,
|
||||
|
@ -216,6 +220,10 @@ impl From<Task> for TaskView {
|
|||
TaskType::IndexUpdate,
|
||||
Some(TaskDetails::IndexInfo { primary_key }),
|
||||
),
|
||||
TaskContent::Dump { uid } => (
|
||||
TaskType::DumpCreation,
|
||||
Some(TaskDetails::Dump { dump_uid: uid }),
|
||||
),
|
||||
};
|
||||
|
||||
// An event always has at least one event: "Created"
|
||||
|
@ -313,7 +321,7 @@ impl From<Task> for TaskView {
|
|||
|
||||
Self {
|
||||
uid: id,
|
||||
index_uid: index_uid.into_inner(),
|
||||
index_uid: index_uid.map(|u| u.into_inner()),
|
||||
status,
|
||||
task_type,
|
||||
details,
|
||||
|
@ -342,7 +350,7 @@ impl From<Vec<TaskView>> for TaskListView {
|
|||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SummarizedTaskView {
|
||||
uid: TaskId,
|
||||
index_uid: String,
|
||||
index_uid: Option<String>,
|
||||
status: TaskStatus,
|
||||
#[serde(rename = "type")]
|
||||
task_type: TaskType,
|
||||
|
@ -365,7 +373,7 @@ impl From<Task> for SummarizedTaskView {
|
|||
|
||||
Self {
|
||||
uid: other.id,
|
||||
index_uid: other.index_uid.to_string(),
|
||||
index_uid: other.index_uid.map(|u| u.into_inner()),
|
||||
status: TaskStatus::Enqueued,
|
||||
task_type: other.content.into(),
|
||||
enqueued_at,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue