Port queue page

This commit is contained in:
Joscha 2023-08-14 12:10:05 +02:00
parent 123c27e5a2
commit 2b6c339c70
7 changed files with 44 additions and 19 deletions

View file

@ -1,4 +1,3 @@
const COUNT = document.getElementById("count")!;
const INNER = document.getElementById("inner")!;
const REFRESH_SECONDS = 10;
@ -7,7 +6,7 @@ function update() {
.then(response => response.text())
.then(text => {
INNER.innerHTML = text;
let count = INNER.querySelector<HTMLElement>("#queue")?.dataset["count"]!;
let count = document.getElementById("queue")?.dataset["count"]!;
document.title = document.title.replace(/^queue \(\d+\)/, `queue (${count})`);
});
}

View file

@ -4,7 +4,6 @@ mod base;
mod link;
mod pages;
pub mod paths;
mod queue;
mod r#static;
use axum::{routing::get, Router};
@ -19,10 +18,12 @@ use self::{
post_api_worker_status,
},
pages::{
commit::get_commit_by_hash, index::get_index, run::get_run_by_id,
commit::get_commit_by_hash,
index::get_index,
queue::{get_queue, get_queue_inner},
run::get_run_by_id,
worker::get_worker_by_name,
},
queue::{get_queue, get_queue_inner},
};
use super::Server;

View file

@ -1,4 +1,5 @@
pub mod commit;
pub mod index;
pub mod queue;
pub mod run;
pub mod worker;

View file

@ -12,19 +12,21 @@ use crate::{
config::Config,
server::{
util,
web::{
base::{Base, Link, Tab},
link::{LinkCommit, LinkRunShort, LinkWorker},
paths::{
PathAdminQueueDecrease, PathAdminQueueDelete, PathAdminQueueIncrease, PathQueue,
PathQueueInner,
},
r#static::QUEUE_JS,
},
workers::{WorkerInfo, Workers},
},
shared::WorkerStatus,
somehow,
};
use super::{
base::{Base, Link, Tab},
link::{LinkCommit, LinkRunShort, LinkWorker},
paths::{PathQueue, PathQueueInner},
r#static::QUEUE_JS,
};
enum Status {
Idle,
Busy,
@ -37,6 +39,10 @@ struct Worker {
}
struct Task {
link_delete: Link,
link_increase: Link,
link_decrease: Link,
hash: String,
commit: LinkCommit,
since: String,
priority: i64,
@ -121,6 +127,10 @@ async fn get_queue_data(
)
.fetch(db)
.map_ok(|r| Task {
link_delete: base.link(PathAdminQueueDelete {}),
link_increase: base.link(PathAdminQueueIncrease {}),
link_decrease: base.link(PathAdminQueueDecrease {}),
hash: r.hash.clone(),
workers: workers_by_commit.remove(&r.hash).unwrap_or_default(),
commit: LinkCommit::new(base, r.hash, &r.message, r.reachable),
since: util::format_delta_from_now(r.date),
@ -144,7 +154,7 @@ async fn get_queue_data(
}
#[derive(Template)]
#[template(path = "queue_inner.html")]
#[template(path = "pages/queue_inner.html")]
struct QueueInnerTemplate {
workers: Vec<Worker>,
tasks: Vec<Task>,
@ -163,7 +173,7 @@ pub async fn get_queue_inner(
Ok(QueueInnerTemplate { workers, tasks })
}
#[derive(Template)]
#[template(path = "queue.html")]
#[template(path = "pages/queue.html")]
struct QueueTemplate {
link_queue_js: Link,
base: Base,

View file

@ -10,7 +10,7 @@ use serde::Deserialize;
pub struct PathIndex {}
#[derive(Deserialize, TypedPath)]
#[typed_path("/queue")]
#[typed_path("/queue/")]
pub struct PathQueue {}
#[derive(Deserialize, TypedPath)]

View file

@ -1,6 +1,5 @@
{% import "util.html" as util %}
<h2>Workers</h2>
{% if workers.is_empty() %}
<p>No workers connected</p>
{% else %}
@ -30,6 +29,7 @@
{% endif %}
<h2>Queue ({{ tasks.len() }})</h2>
<table id="queue" data-count="{{ tasks.len() }}">
<thead>
<tr>
@ -43,8 +43,21 @@
{% for task in tasks %}
<tr {% if task.odd %} class="odd" {% endif %}>
<td>{{ task.commit|safe }}</td>
<td>{{ task.since }}</td>
<td>{{ task.priority }}</td>
<td>
{{ task.since }}
[<a href="{{ task.link_delete }}" title="Delete from queue">del</a>]
</td>
<td>
{{ task.priority }}
[<form method="post" action="{{ task.link_increase }}">
<input type="hidden" name="hash" value="{{ task.hash }}">
<button title="Increase priority by 1">inc</button>
</form>,
<form method="post" action="{{ task.link_decrease }}">
<input type="hidden" name="hash" value="{{ task.hash }}">
<button title="Decrease priority by 1">dec</button>
</form>]
</td>
{% if task.workers.is_empty() %}
<td>-</td>
{% else %}
@ -53,4 +66,5 @@
</tr>
{% endfor %}
</tbody>
</table>