MeiliSearch/meilisearch-http/src/routes/dump.rs

32 lines
1.1 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;
use log::debug;
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;
2020-12-12 13:32:06 +01:00
2021-10-14 11:32:55 +02:00
use crate::analytics::Analytics;
2021-06-24 15:06:58 +02:00
use crate::extractors::authentication::{policies::*, GuardedData};
2022-03-04 20:12:44 +01:00
use crate::extractors::sequential_extractor::SeqHandler;
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>>,
2021-10-14 11:32:55 +02:00
req: HttpRequest,
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));
let task = KindWithContent::DumpExport {
2022-09-27 16:33:37 +02:00
output: "todo".to_string().into(),
};
2022-09-27 16:33:37 +02:00
let res = tokio::task::spawn_blocking(move || index_scheduler.register(task)).await??;
2021-05-05 14:11:56 +02:00
2021-06-23 12:18:34 +02:00
debug!("returns: {:?}", res);
Ok(HttpResponse::Accepted().json(res))
2020-12-12 13:32:06 +01:00
}