2023-09-11 11:00:05 +02:00
|
|
|
use actix_web::web::Data;
|
|
|
|
use actix_web::{web, HttpRequest, HttpResponse};
|
|
|
|
use index_scheduler::IndexScheduler;
|
|
|
|
use meilisearch_types::error::ResponseError;
|
|
|
|
use meilisearch_types::tasks::KindWithContent;
|
|
|
|
use serde_json::json;
|
2024-02-08 10:14:50 +01:00
|
|
|
use tracing::debug;
|
2023-09-11 11:00:05 +02:00
|
|
|
|
|
|
|
use crate::analytics::Analytics;
|
|
|
|
use crate::extractors::authentication::policies::*;
|
|
|
|
use crate::extractors::authentication::GuardedData;
|
|
|
|
use crate::extractors::sequential_extractor::SeqHandler;
|
2023-09-07 11:16:51 +02:00
|
|
|
use crate::routes::{get_task_id, SummarizedTaskView};
|
2024-02-20 11:24:44 +01:00
|
|
|
use crate::Opt;
|
2023-09-11 11:00:05 +02:00
|
|
|
|
|
|
|
pub fn configure(cfg: &mut web::ServiceConfig) {
|
|
|
|
cfg.service(web::resource("").route(web::post().to(SeqHandler(create_snapshot))));
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn create_snapshot(
|
|
|
|
index_scheduler: GuardedData<ActionPolicy<{ actions::SNAPSHOTS_CREATE }>, Data<IndexScheduler>>,
|
|
|
|
req: HttpRequest,
|
2024-02-20 11:24:44 +01:00
|
|
|
opt: web::Data<Opt>,
|
2023-09-11 11:00:05 +02:00
|
|
|
analytics: web::Data<dyn Analytics>,
|
|
|
|
) -> Result<HttpResponse, ResponseError> {
|
|
|
|
analytics.publish("Snapshot Created".to_string(), json!({}), Some(&req));
|
|
|
|
|
|
|
|
let task = KindWithContent::SnapshotCreation;
|
2024-02-20 11:24:44 +01:00
|
|
|
let uid = get_task_id(&req, &opt)?;
|
2023-09-11 11:00:05 +02:00
|
|
|
let task: SummarizedTaskView =
|
2023-09-07 11:16:51 +02:00
|
|
|
tokio::task::spawn_blocking(move || index_scheduler.register(task, uid)).await??.into();
|
2023-09-11 11:00:05 +02:00
|
|
|
|
2024-02-08 10:14:50 +01:00
|
|
|
debug!(returns = ?task, "Create snapshot");
|
2023-09-11 11:00:05 +02:00
|
|
|
Ok(HttpResponse::Accepted().json(task))
|
|
|
|
}
|