Put the original URL query in the tasks details

This commit is contained in:
Kerollmops 2022-10-18 17:47:47 +02:00 committed by Clément Renault
parent 751e9bac3b
commit c2ec4a089b
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
3 changed files with 18 additions and 10 deletions

View File

@ -496,7 +496,7 @@ impl IndexScheduler {
}; };
let mut wtxn = self.env.write_txn()?; let mut wtxn = self.env.write_txn()?;
let nbr_deleted_tasks = self.delete_matched_tasks(&mut wtxn, matched_tasks)?; let deleted_tasks_count = self.delete_matched_tasks(&mut wtxn, matched_tasks)?;
task.status = Status::Succeeded; task.status = Status::Succeeded;
match &mut task.details { match &mut task.details {
@ -505,7 +505,7 @@ impl IndexScheduler {
deleted_tasks, deleted_tasks,
original_query: _, original_query: _,
}) => { }) => {
*deleted_tasks = Some(nbr_deleted_tasks); *deleted_tasks = Some(deleted_tasks_count);
} }
_ => unreachable!(), _ => unreachable!(),
} }

View File

@ -213,6 +213,7 @@ pub struct TaskCancelationQuery {
async fn cancel_tasks( async fn cancel_tasks(
index_scheduler: GuardedData<ActionPolicy<{ actions::TASKS_CANCEL }>, Data<IndexScheduler>>, index_scheduler: GuardedData<ActionPolicy<{ actions::TASKS_CANCEL }>, Data<IndexScheduler>>,
req: HttpRequest,
params: web::Query<TaskCancelationQuery>, params: web::Query<TaskCancelationQuery>,
) -> Result<HttpResponse, ResponseError> { ) -> Result<HttpResponse, ResponseError> {
let TaskCancelationQuery { let TaskCancelationQuery {
@ -243,12 +244,12 @@ async fn cancel_tasks(
let filtered_query = filter_out_inaccessible_indexes_from_query(&index_scheduler, &query); let filtered_query = filter_out_inaccessible_indexes_from_query(&index_scheduler, &query);
let tasks = index_scheduler.get_task_ids(&filtered_query)?; let tasks = index_scheduler.get_task_ids(&filtered_query)?;
let filtered_query_string = yaup::to_string(&filtered_query).unwrap();
let task_cancelation = KindWithContent::TaskCancelation { let task_cancelation = KindWithContent::TaskCancelation {
query: filtered_query_string, query: req.query_string().to_string(),
tasks, tasks,
}; };
// TODO add a tokio_spawn
let task = index_scheduler.register(task_cancelation)?; let task = index_scheduler.register(task_cancelation)?;
let task_view = TaskView::from_task(&task); let task_view = TaskView::from_task(&task);
@ -257,6 +258,7 @@ async fn cancel_tasks(
async fn delete_tasks( async fn delete_tasks(
index_scheduler: GuardedData<ActionPolicy<{ actions::TASKS_DELETE }>, Data<IndexScheduler>>, index_scheduler: GuardedData<ActionPolicy<{ actions::TASKS_DELETE }>, Data<IndexScheduler>>,
req: HttpRequest,
params: web::Query<TaskDeletionQuery>, params: web::Query<TaskDeletionQuery>,
) -> Result<HttpResponse, ResponseError> { ) -> Result<HttpResponse, ResponseError> {
let TaskDeletionQuery { let TaskDeletionQuery {
@ -287,12 +289,12 @@ async fn delete_tasks(
let filtered_query = filter_out_inaccessible_indexes_from_query(&index_scheduler, &query); let filtered_query = filter_out_inaccessible_indexes_from_query(&index_scheduler, &query);
let tasks = index_scheduler.get_task_ids(&filtered_query)?; let tasks = index_scheduler.get_task_ids(&filtered_query)?;
let filtered_query_string = yaup::to_string(&filtered_query).unwrap();
let task_deletion = KindWithContent::TaskDeletion { let task_deletion = KindWithContent::TaskDeletion {
query: filtered_query_string, query: req.query_string().to_string(),
tasks, tasks,
}; };
// TODO add a tokio_spawn
let task = index_scheduler.register(task_deletion)?; let task = index_scheduler.register(task_deletion)?;
let task_view = TaskView::from_task(&task); let task_view = TaskView::from_task(&task);

View File

@ -215,9 +215,11 @@ impl KindWithContent {
KindWithContent::IndexSwap { .. } => { KindWithContent::IndexSwap { .. } => {
todo!() todo!()
} }
KindWithContent::TaskCancelation { .. } => { KindWithContent::TaskCancelation { query, tasks } => Some(Details::TaskCancelation {
None // TODO: check correctness of this return value matched_tasks: tasks.len(),
} canceled_tasks: None,
original_query: query.clone(),
}),
KindWithContent::TaskDeletion { query, tasks } => Some(Details::TaskDeletion { KindWithContent::TaskDeletion { query, tasks } => Some(Details::TaskDeletion {
matched_tasks: tasks.len(), matched_tasks: tasks.len(),
deleted_tasks: None, deleted_tasks: None,
@ -251,7 +253,11 @@ impl From<&KindWithContent> for Option<Details> {
primary_key: primary_key.clone(), primary_key: primary_key.clone(),
}), }),
KindWithContent::IndexSwap { .. } => None, KindWithContent::IndexSwap { .. } => None,
KindWithContent::TaskCancelation { .. } => None, KindWithContent::TaskCancelation { query, tasks } => Some(Details::TaskCancelation {
matched_tasks: tasks.len(),
canceled_tasks: None,
original_query: query.clone(),
}),
KindWithContent::TaskDeletion { query, tasks } => Some(Details::TaskDeletion { KindWithContent::TaskDeletion { query, tasks } => Some(Details::TaskDeletion {
matched_tasks: tasks.len(), matched_tasks: tasks.len(),
deleted_tasks: None, deleted_tasks: None,