Add admin button to update repo
This commit is contained in:
parent
6cf7a0b586
commit
4f2b0a0b88
9 changed files with 69 additions and 15 deletions
|
|
@ -4,14 +4,17 @@ mod fetch;
|
|||
mod queue;
|
||||
mod repo;
|
||||
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use super::{Repo, Server};
|
||||
|
||||
pub(super) async fn run(server: Server, repo: Repo) {
|
||||
pub(super) async fn run(server: Server, repo: Repo, mut recurring_rx: mpsc::UnboundedReceiver<()>) {
|
||||
loop {
|
||||
fetch::update(server.config, repo.clone()).await;
|
||||
repo::update(&server.db, repo.clone()).await;
|
||||
queue::update(&server.db).await;
|
||||
|
||||
tokio::time::sleep(server.config.repo_update).await;
|
||||
let _ = tokio::time::timeout(server.config.repo_update, recurring_rx.recv()).await;
|
||||
while let Ok(()) = recurring_rx.try_recv() {}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,12 @@ use axum_extra::routing::RouterExt;
|
|||
use crate::somehow;
|
||||
|
||||
use self::{
|
||||
admin::queue::{
|
||||
post_admin_queue_add, post_admin_queue_decrease, post_admin_queue_delete,
|
||||
post_admin_queue_increase,
|
||||
admin::{
|
||||
queue::{
|
||||
post_admin_queue_add, post_admin_queue_decrease, post_admin_queue_delete,
|
||||
post_admin_queue_increase,
|
||||
},
|
||||
repo::post_admin_repo_update,
|
||||
},
|
||||
api::worker::{
|
||||
get_api_worker_bench_repo_by_hash_tree_tar_gz, get_api_worker_repo_by_hash_tree_tar_gz,
|
||||
|
|
@ -55,6 +58,7 @@ pub async fn run(server: Server) -> somehow::Result<()> {
|
|||
.typed_post(post_admin_queue_decrease)
|
||||
.typed_post(post_admin_queue_delete)
|
||||
.typed_post(post_admin_queue_increase)
|
||||
.typed_post(post_admin_repo_update)
|
||||
.merge(post_api_worker_status)
|
||||
.fallback(get(r#static::static_handler))
|
||||
.with_state(server.clone());
|
||||
|
|
|
|||
|
|
@ -1 +1,2 @@
|
|||
pub mod queue;
|
||||
pub mod repo;
|
||||
|
|
|
|||
29
src/server/web/admin/repo.rs
Normal file
29
src/server/web/admin/repo.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use axum::{
|
||||
extract::State,
|
||||
response::{IntoResponse, Redirect},
|
||||
};
|
||||
use log::info;
|
||||
use tokio::sync::mpsc;
|
||||
|
||||
use crate::{
|
||||
config::ServerConfig,
|
||||
server::web::{
|
||||
base::Base,
|
||||
paths::{PathAdminRepoUpdate, PathIndex},
|
||||
},
|
||||
somehow,
|
||||
};
|
||||
|
||||
pub async fn post_admin_repo_update(
|
||||
_path: PathAdminRepoUpdate,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(recurring_tx): State<Arc<mpsc::UnboundedSender<()>>>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let _ = recurring_tx.send(());
|
||||
info!("Admin updated repo");
|
||||
|
||||
let link = Base::link_with_config(config, PathIndex {});
|
||||
Ok(Redirect::to(&link.to_string()))
|
||||
}
|
||||
|
|
@ -6,9 +6,9 @@ use sqlx::SqlitePool;
|
|||
use crate::{
|
||||
config::ServerConfig,
|
||||
server::web::{
|
||||
base::{Base, Tab},
|
||||
base::{Base, Link, Tab},
|
||||
link::LinkCommit,
|
||||
paths::PathIndex,
|
||||
paths::{PathAdminRepoUpdate, PathIndex},
|
||||
},
|
||||
somehow,
|
||||
};
|
||||
|
|
@ -22,7 +22,9 @@ struct Ref {
|
|||
#[derive(Template)]
|
||||
#[template(path = "pages/index.html")]
|
||||
struct IndexTemplate {
|
||||
link_admin_repo_update: Link,
|
||||
base: Base,
|
||||
|
||||
tracked_refs: Vec<Ref>,
|
||||
untracked_refs: Vec<Ref>,
|
||||
}
|
||||
|
|
@ -62,7 +64,9 @@ pub async fn get_index(
|
|||
}
|
||||
|
||||
Ok(IndexTemplate {
|
||||
link_admin_repo_update: base.link(PathAdminRepoUpdate {}),
|
||||
base: Base::new(config, Tab::Index),
|
||||
|
||||
tracked_refs,
|
||||
untracked_refs,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ pub struct PathWorkerByName {
|
|||
// Admin actions //
|
||||
///////////////////
|
||||
|
||||
#[derive(Deserialize, TypedPath)]
|
||||
#[typed_path("/admin/repo/update")]
|
||||
pub struct PathAdminRepoUpdate {}
|
||||
|
||||
#[derive(Deserialize, TypedPath)]
|
||||
#[typed_path("/admin/queue/add")]
|
||||
pub struct PathAdminQueueAdd {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue