Implement more /admin/queue/* endpoints

This commit is contained in:
Joscha 2023-08-14 12:18:43 +02:00
parent 1da946be10
commit 7f975a1fd0
4 changed files with 98 additions and 2 deletions

View file

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "UPDATE queue SET priority = priority - 1 WHERE hash = ?",
"describe": {
"columns": [],
"parameters": {
"Right": 1
},
"nullable": []
},
"hash": "57059622ba187e7cf18cad5e44f5cd5d4bc31689e23bec53d1078ea98ad7a298"
}

View file

@ -0,0 +1,12 @@
{
"db_name": "SQLite",
"query": "UPDATE queue SET priority = priority + 1 WHERE hash = ?",
"describe": {
"columns": [],
"parameters": {
"Right": 1
},
"nullable": []
},
"hash": "e66cd6d7e9a4b0798a9b301a473582f50c07245e0274aa23b281e0bd5e3b67f5"
}

View file

@ -12,7 +12,10 @@ use axum_extra::routing::RouterExt;
use crate::somehow;
use self::{
admin::queue::post_admin_queue_add,
admin::queue::{
post_admin_queue_add, post_admin_queue_decrease, post_admin_queue_delete,
post_admin_queue_increase,
},
api::worker::{
get_api_worker_bench_repo_by_hash_tree_tar_gz, get_api_worker_repo_by_hash_tree_tar_gz,
post_api_worker_status,
@ -41,6 +44,9 @@ pub async fn run(server: Server) -> somehow::Result<()> {
.typed_get(get_run_by_id)
.typed_get(get_worker_by_name)
.typed_post(post_admin_queue_add)
.typed_post(post_admin_queue_decrease)
.typed_post(post_admin_queue_delete)
.typed_post(post_admin_queue_increase)
.typed_post(post_api_worker_status)
.fallback(get(r#static::static_handler))
.with_state(server.clone());

View file

@ -11,7 +11,10 @@ use crate::{
config::Config,
server::web::{
base::Base,
paths::{PathAdminQueueAdd, PathQueue},
paths::{
PathAdminQueueAdd, PathAdminQueueDecrease, PathAdminQueueDelete,
PathAdminQueueIncrease, PathQueue,
},
},
somehow,
};
@ -46,3 +49,66 @@ pub async fn post_admin_queue_add(
let link = Base::link_with_config(config, PathQueue {});
Ok(Redirect::to(&format!("{link}")))
}
#[derive(Deserialize)]
pub struct FormAdminQueueDelete {
hash: String,
}
pub async fn post_admin_queue_delete(
_path: PathAdminQueueDelete,
State(config): State<&'static Config>,
State(db): State<SqlitePool>,
Form(form): Form<FormAdminQueueDelete>,
) -> somehow::Result<impl IntoResponse> {
sqlx::query!("DELETE FROM queue WHERE hash = ?", form.hash)
.execute(&db)
.await?;
let link = Base::link_with_config(config, PathQueue {});
Ok(Redirect::to(&format!("{link}")))
}
#[derive(Deserialize)]
pub struct FormAdminQueueIncrease {
hash: String,
}
pub async fn post_admin_queue_increase(
_path: PathAdminQueueIncrease,
State(config): State<&'static Config>,
State(db): State<SqlitePool>,
Form(form): Form<FormAdminQueueIncrease>,
) -> somehow::Result<impl IntoResponse> {
sqlx::query!(
"UPDATE queue SET priority = priority + 1 WHERE hash = ?",
form.hash
)
.execute(&db)
.await?;
let link = Base::link_with_config(config, PathQueue {});
Ok(Redirect::to(&format!("{link}")))
}
#[derive(Deserialize)]
pub struct FormAdminQueueDecrease {
hash: String,
}
pub async fn post_admin_queue_decrease(
_path: PathAdminQueueDecrease,
State(config): State<&'static Config>,
State(db): State<SqlitePool>,
Form(form): Form<FormAdminQueueDecrease>,
) -> somehow::Result<impl IntoResponse> {
sqlx::query!(
"UPDATE queue SET priority = priority - 1 WHERE hash = ?",
form.hash
)
.execute(&db)
.await?;
let link = Base::link_with_config(config, PathQueue {});
Ok(Redirect::to(&format!("{link}")))
}