MeiliSearch/meilisearch/src/routes/dump.rs

44 lines
1.6 KiB
Rust
Raw Normal View History

2022-09-27 16:33:37 +02:00
use actix_web::web::Data;
2021-10-14 11:32:55 +02:00
use actix_web::{web, HttpRequest, HttpResponse};
2022-09-27 16:33:37 +02:00
use index_scheduler::IndexScheduler;
2022-10-13 15:02:59 +02:00
use meilisearch_auth::AuthController;
use meilisearch_types::error::ResponseError;
2022-10-12 03:21:25 +02:00
use meilisearch_types::tasks::KindWithContent;
2021-10-14 11:32:55 +02:00
use serde_json::json;
2024-02-08 10:14:50 +01:00
use tracing::debug;
2020-12-12 13:32:06 +01:00
2021-10-14 11:32:55 +02:00
use crate::analytics::Analytics;
2022-10-20 18:00:07 +02:00
use crate::extractors::authentication::policies::*;
use crate::extractors::authentication::GuardedData;
2022-03-04 20:12:44 +01:00
use crate::extractors::sequential_extractor::SeqHandler;
2024-02-21 11:21:26 +01:00
use crate::routes::{get_task_id, is_dry_run, SummarizedTaskView};
use crate::Opt;
2020-12-12 13:32:06 +01:00
2021-07-05 14:29:20 +02:00
pub fn configure(cfg: &mut web::ServiceConfig) {
2022-05-19 20:19:34 +02:00
cfg.service(web::resource("").route(web::post().to(SeqHandler(create_dump))));
2020-12-12 13:32:06 +01:00
}
2021-09-28 22:22:59 +02:00
pub async fn create_dump(
2022-09-27 16:33:37 +02:00
index_scheduler: GuardedData<ActionPolicy<{ actions::DUMPS_CREATE }>, Data<IndexScheduler>>,
auth_controller: GuardedData<ActionPolicy<{ actions::DUMPS_CREATE }>, Data<AuthController>>,
2021-10-14 11:32:55 +02:00
req: HttpRequest,
opt: web::Data<Opt>,
2021-10-29 16:10:58 +02:00
analytics: web::Data<dyn Analytics>,
2021-09-28 22:22:59 +02:00
) -> Result<HttpResponse, ResponseError> {
2021-10-14 11:32:55 +02:00
analytics.publish("Dump Created".to_string(), json!({}), Some(&req));
2022-10-24 19:08:15 +02:00
let task = KindWithContent::DumpCreation {
2022-10-13 15:02:59 +02:00
keys: auth_controller.list_keys()?,
instance_uid: analytics.instance_uid().cloned(),
};
let uid = get_task_id(&req, &opt)?;
2024-02-21 11:21:26 +01:00
let dry_run = is_dry_run(&req, &opt)?;
2022-10-13 15:02:59 +02:00
let task: SummarizedTaskView =
2024-02-21 11:21:26 +01:00
tokio::task::spawn_blocking(move || index_scheduler.register(task, uid, dry_run))
.await??
.into();
2021-05-05 14:11:56 +02:00
2024-02-08 10:14:50 +01:00
debug!(returns = ?task, "Create dump");
2022-10-13 15:02:59 +02:00
Ok(HttpResponse::Accepted().json(task))
2020-12-12 13:32:06 +01:00
}