Add the tasks cancel route to cancel tasks

This commit is contained in:
Kerollmops 2022-10-18 14:48:40 +02:00 committed by Clément Renault
parent 290945e258
commit 751e9bac3b
No known key found for this signature in database
GPG key ID: 92ADA4E935E71FA4
6 changed files with 73 additions and 8 deletions

View file

@ -17,9 +17,10 @@ pub enum Error {
CorruptedDump,
#[error("Task `{0}` not found")]
TaskNotFound(TaskId),
// TODO: Lo: proper error message for this
#[error("Cannot delete all tasks")]
#[error("Query parameters to filter the tasks to delete are missing. Available query parameters are: `uid`, `indexUid`, `status`, `type`")]
TaskDeletionWithEmptyQuery,
#[error("Query parameters to filter the tasks to cancel are missing. Available query parameters are: `uid`, `indexUid`, `status`, `type`")]
TaskCancelationWithEmptyQuery,
// maybe the two next errors are going to move to the frontend
#[error("`{0}` is not a status. Available status are")]
InvalidStatus(String),
@ -48,6 +49,7 @@ impl ErrorCode for Error {
Error::IndexAlreadyExists(_) => Code::IndexAlreadyExists,
Error::TaskNotFound(_) => Code::TaskNotFound,
Error::TaskDeletionWithEmptyQuery => Code::TaskDeletionWithEmptyQuery,
Error::TaskCancelationWithEmptyQuery => Code::TaskCancelationWithEmptyQuery,
Error::InvalidStatus(_) => Code::BadRequest,
Error::InvalidKind(_) => Code::BadRequest,

View file

@ -829,7 +829,7 @@ mod tests {
replace_document_import_task("catto", None, 0, 12),
KindWithContent::TaskCancelation {
query: format!("uid=0,1"),
tasks: vec![0, 1],
tasks: RoaringBitmap::from_iter([0, 1]),
},
replace_document_import_task("catto", None, 1, 50),
replace_document_import_task("doggo", Some("bone"), 2, 5000),

View file

@ -104,6 +104,7 @@ fn snapshot_task(task: &Task) -> String {
started_at: _,
finished_at: _,
error,
canceled_by: _,
details,
status,
kind,