Add button to batch-queue commits without runs
This commit is contained in:
parent
238ce5e463
commit
af11d54d0c
7 changed files with 90 additions and 14 deletions
|
|
@ -13,8 +13,8 @@ use crate::{
|
|||
server::web::{
|
||||
base::Base,
|
||||
paths::{
|
||||
PathAdminQueueAdd, PathAdminQueueDecrease, PathAdminQueueDelete,
|
||||
PathAdminQueueIncrease, PathQueue,
|
||||
PathAdminQueueAdd, PathAdminQueueAddBatch, PathAdminQueueDecrease,
|
||||
PathAdminQueueDelete, PathAdminQueueIncrease, PathQueue,
|
||||
},
|
||||
},
|
||||
somehow,
|
||||
|
|
@ -56,6 +56,49 @@ pub async fn post_admin_queue_add(
|
|||
Ok(Redirect::to(&format!("{link}")))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct FormAdminQueueAddBatch {
|
||||
amount: u32,
|
||||
#[serde(default)]
|
||||
priority: i32,
|
||||
}
|
||||
|
||||
pub async fn post_admin_queue_add_batch(
|
||||
_path: PathAdminQueueAddBatch,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
Form(form): Form<FormAdminQueueAddBatch>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let date = OffsetDateTime::now_utc();
|
||||
let added = sqlx::query!(
|
||||
"\
|
||||
INSERT OR IGNORE INTO queue (hash, date, priority) \
|
||||
SELECT hash, ?, ? \
|
||||
FROM commits \
|
||||
LEFT JOIN runs USING (hash) \
|
||||
WHERE reachable = 2 AND id IS NULL \
|
||||
ORDER BY unixepoch(committer_date) DESC \
|
||||
LIMIT ? \
|
||||
",
|
||||
date,
|
||||
form.priority,
|
||||
form.amount,
|
||||
)
|
||||
.execute(&db)
|
||||
.await?
|
||||
.rows_affected();
|
||||
|
||||
if added > 0 {
|
||||
info!(
|
||||
"Admin batch-added {added} commits to queue with priority {}",
|
||||
form.priority,
|
||||
);
|
||||
}
|
||||
|
||||
let link = Base::link_with_config(config, PathQueue {});
|
||||
Ok(Redirect::to(&format!("{link}")))
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct FormAdminQueueDelete {
|
||||
hash: String,
|
||||
|
|
|
|||
|
|
@ -20,8 +20,8 @@ use crate::{
|
|||
base::{Base, Link, Tab},
|
||||
link::{LinkCommit, LinkRunShort, LinkWorker},
|
||||
paths::{
|
||||
PathAdminQueueDecrease, PathAdminQueueDelete, PathAdminQueueIncrease, PathQueue,
|
||||
PathQueueDelete, PathQueueInner,
|
||||
PathAdminQueueAddBatch, PathAdminQueueDecrease, PathAdminQueueDelete,
|
||||
PathAdminQueueIncrease, PathQueue, PathQueueDelete, PathQueueInner,
|
||||
},
|
||||
r#static::QUEUE_JS,
|
||||
},
|
||||
|
|
@ -155,6 +155,7 @@ async fn get_queue_data(
|
|||
#[derive(Template)]
|
||||
#[template(path = "pages/queue_inner.html")]
|
||||
struct PageInner {
|
||||
link_admin_queue_add_batch: Link,
|
||||
workers: Vec<Worker>,
|
||||
tasks: Vec<Task>,
|
||||
}
|
||||
|
|
@ -167,9 +168,11 @@ pub async fn get_queue_inner(
|
|||
) -> somehow::Result<impl IntoResponse> {
|
||||
let base = Base::new(config, Tab::Queue);
|
||||
let sorted_workers = sorted_workers(&workers);
|
||||
let workers = get_workers(&db, &sorted_workers, &base).await?;
|
||||
let tasks = get_queue_data(&db, &sorted_workers, &base).await?;
|
||||
Ok(PageInner { workers, tasks })
|
||||
Ok(PageInner {
|
||||
link_admin_queue_add_batch: base.link(PathAdminQueueAddBatch {}),
|
||||
workers: get_workers(&db, &sorted_workers, &base).await?,
|
||||
tasks: get_queue_data(&db, &sorted_workers, &base).await?,
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Template)]
|
||||
|
|
@ -188,12 +191,14 @@ pub async fn get_queue(
|
|||
) -> somehow::Result<impl IntoResponse> {
|
||||
let base = Base::new(config, Tab::Queue);
|
||||
let sorted_workers = sorted_workers(&workers);
|
||||
let workers = get_workers(&db, &sorted_workers, &base).await?;
|
||||
let tasks = get_queue_data(&db, &sorted_workers, &base).await?;
|
||||
Ok(Page {
|
||||
link_queue_js: base.link(QUEUE_JS),
|
||||
inner: PageInner {
|
||||
link_admin_queue_add_batch: base.link(PathAdminQueueAddBatch {}),
|
||||
workers: get_workers(&db, &sorted_workers, &base).await?,
|
||||
tasks: get_queue_data(&db, &sorted_workers, &base).await?,
|
||||
},
|
||||
base,
|
||||
inner: PageInner { workers, tasks },
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -61,6 +61,10 @@ pub struct PathAdminRepoUpdate {}
|
|||
#[typed_path("/admin/queue/add")]
|
||||
pub struct PathAdminQueueAdd {}
|
||||
|
||||
#[derive(Deserialize, TypedPath)]
|
||||
#[typed_path("/admin/queue/add_batch")]
|
||||
pub struct PathAdminQueueAddBatch {}
|
||||
|
||||
#[derive(Deserialize, TypedPath)]
|
||||
#[typed_path("/admin/queue/delete")]
|
||||
pub struct PathAdminQueueDelete {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue