register dump tasks

This commit is contained in:
ad hoc 2022-05-17 17:40:59 +02:00
parent 2f0625a984
commit 7fa3eb1003
No known key found for this signature in database
GPG Key ID: 4F00A782990CC643
3 changed files with 9 additions and 5 deletions

View File

@ -8,6 +8,7 @@ use serde_json::json;
use crate::analytics::Analytics; use crate::analytics::Analytics;
use crate::extractors::authentication::{policies::*, GuardedData}; use crate::extractors::authentication::{policies::*, GuardedData};
use crate::extractors::sequential_extractor::SeqHandler; use crate::extractors::sequential_extractor::SeqHandler;
use crate::task::SummarizedTaskView;
pub fn configure(cfg: &mut web::ServiceConfig) { pub fn configure(cfg: &mut web::ServiceConfig) {
cfg.service(web::resource("").route(web::post().to(SeqHandler(create_dump)))) cfg.service(web::resource("").route(web::post().to(SeqHandler(create_dump))))
@ -23,7 +24,7 @@ pub async fn create_dump(
) -> Result<HttpResponse, ResponseError> { ) -> Result<HttpResponse, ResponseError> {
analytics.publish("Dump Created".to_string(), json!({}), Some(&req)); 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); debug!("returns: {:?}", res);
Ok(HttpResponse::Accepted().json(res)) Ok(HttpResponse::Accepted().json(res))

View File

@ -24,6 +24,7 @@ enum TaskType {
DocumentDeletion, DocumentDeletion,
SettingsUpdate, SettingsUpdate,
ClearAll, ClearAll,
Dump,
} }
impl From<TaskContent> for TaskType { impl From<TaskContent> for TaskType {
@ -43,6 +44,7 @@ impl From<TaskContent> for TaskType {
TaskContent::IndexDeletion => TaskType::IndexDeletion, TaskContent::IndexDeletion => TaskType::IndexDeletion,
TaskContent::IndexCreation { .. } => TaskType::IndexCreation, TaskContent::IndexCreation { .. } => TaskType::IndexCreation,
TaskContent::IndexUpdate { .. } => TaskType::IndexUpdate, TaskContent::IndexUpdate { .. } => TaskType::IndexUpdate,
TaskContent::Dump { path } => TaskType::Dump,
_ => unreachable!("unexpected task type"), _ => unreachable!("unexpected task type"),
} }
} }
@ -216,7 +218,7 @@ impl From<Task> for TaskView {
TaskType::IndexUpdate, TaskType::IndexUpdate,
Some(TaskDetails::IndexInfo { primary_key }), Some(TaskDetails::IndexInfo { primary_key }),
), ),
TaskContent::Dump { path: _ } => todo!(), TaskContent::Dump { path: _ } => (TaskType::Dump, None),
}; };
// An event always has at least one event: "Created" // An event always has at least one event: "Created"

View File

@ -108,9 +108,10 @@ impl Store {
pub fn put(&self, txn: &mut RwTxn, task: &Task) -> Result<()> { pub fn put(&self, txn: &mut RwTxn, task: &Task) -> Result<()> {
self.tasks.put(txn, &BEU64::new(task.id), task)?; self.tasks.put(txn, &BEU64::new(task.id), task)?;
self.uids_task_ids // only add the task to the indexes index if it has an index_uid
// TODO(marin): The index uid should be remaped to a task queue identifier here if let Some(ref index_uid) = task.index_uid {
.put(txn, &(&task.index_uid.as_ref().unwrap(), task.id), &())?; self.uids_task_ids.put(txn, &(&index_uid, task.id), &())?;
}
Ok(()) Ok(())
} }