Restructure config file
This commit is contained in:
parent
225250ed4e
commit
a54e842478
18 changed files with 258 additions and 216 deletions
|
|
@ -31,6 +31,6 @@ async fn recurring_task(state: &Server, repo: Repo) {
|
|||
pub(super) async fn run(server: Server, repo: Repo) {
|
||||
loop {
|
||||
recurring_task(&server, repo.clone()).await;
|
||||
tokio::time::sleep(server.config.repo_update_delay).await;
|
||||
tokio::time::sleep(server.config.repo_update).await;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ pub async fn run(server: Server) -> somehow::Result<()> {
|
|||
|
||||
let post_api_worker_status = Router::new()
|
||||
.typed_post(post_api_worker_status)
|
||||
.layer(DefaultBodyLimit::max(server.config.web_worker_max_upload));
|
||||
.layer(DefaultBodyLimit::max(server.config.worker_upload));
|
||||
|
||||
let app = Router::new()
|
||||
.typed_get(get_api_worker_bench_repo_by_hash_tree_tar_gz)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use sqlx::SqlitePool;
|
|||
use time::OffsetDateTime;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
config::ServerConfig,
|
||||
server::web::{
|
||||
base::Base,
|
||||
paths::{
|
||||
|
|
@ -28,7 +28,7 @@ pub struct FormAdminQueueAdd {
|
|||
|
||||
pub async fn post_admin_queue_add(
|
||||
_path: PathAdminQueueAdd,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
Form(form): Form<FormAdminQueueAdd>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
|
|
@ -57,7 +57,7 @@ pub struct FormAdminQueueDelete {
|
|||
|
||||
pub async fn post_admin_queue_delete(
|
||||
_path: PathAdminQueueDelete,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
Form(form): Form<FormAdminQueueDelete>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
|
|
@ -76,7 +76,7 @@ pub struct FormAdminQueueIncrease {
|
|||
|
||||
pub async fn post_admin_queue_increase(
|
||||
_path: PathAdminQueueIncrease,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
Form(form): Form<FormAdminQueueIncrease>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
|
|
@ -98,7 +98,7 @@ pub struct FormAdminQueueDecrease {
|
|||
|
||||
pub async fn post_admin_queue_decrease(
|
||||
_path: PathAdminQueueDecrease,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
Form(form): Form<FormAdminQueueDecrease>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use time::OffsetDateTime;
|
|||
use tracing::debug;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
config::ServerConfig,
|
||||
server::{
|
||||
web::paths::{
|
||||
PathApiWorkerBenchRepoByHashTreeTarGz, PathApiWorkerRepoByHashTreeTarGz,
|
||||
|
|
@ -125,7 +125,7 @@ async fn save_work(
|
|||
|
||||
pub async fn post_api_worker_status(
|
||||
_path: PathApiWorkerStatus,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
State(bench_repo): State<Option<BenchRepo>>,
|
||||
State(workers): State<Arc<Mutex<Workers>>>,
|
||||
|
|
@ -204,7 +204,7 @@ fn stream_response(repo: Arc<ThreadSafeRepository>, id: ObjectId) -> impl IntoRe
|
|||
|
||||
pub async fn get_api_worker_repo_by_hash_tree_tar_gz(
|
||||
path: PathApiWorkerRepoByHashTreeTarGz,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(repo): State<Option<Repo>>,
|
||||
auth: Option<TypedHeader<Authorization<Basic>>>,
|
||||
) -> somehow::Result<Response> {
|
||||
|
|
@ -223,7 +223,7 @@ pub async fn get_api_worker_repo_by_hash_tree_tar_gz(
|
|||
|
||||
pub async fn get_api_worker_bench_repo_by_hash_tree_tar_gz(
|
||||
path: PathApiWorkerBenchRepoByHashTreeTarGz,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(bench_repo): State<Option<BenchRepo>>,
|
||||
auth: Option<TypedHeader<Authorization<Basic>>>,
|
||||
) -> somehow::Result<Response> {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use axum::{
|
|||
TypedHeader,
|
||||
};
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::config::ServerConfig;
|
||||
|
||||
fn is_username_valid(username: &str) -> bool {
|
||||
if username.is_empty() {
|
||||
|
|
@ -19,12 +19,12 @@ fn is_username_valid(username: &str) -> bool {
|
|||
.all(|c| c.is_ascii_alphanumeric() || c == '-' || c == '_' || c == '.')
|
||||
}
|
||||
|
||||
fn is_password_valid(password: &str, config: &'static Config) -> bool {
|
||||
password == config.web_worker_token
|
||||
fn is_password_valid(password: &str, config: &'static ServerConfig) -> bool {
|
||||
password == config.worker_token
|
||||
}
|
||||
|
||||
pub fn authenticate(
|
||||
config: &'static Config,
|
||||
config: &'static ServerConfig,
|
||||
auth: Option<TypedHeader<Authorization<Basic>>>,
|
||||
) -> Result<String, Response> {
|
||||
if let Some(auth) = auth {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use std::fmt;
|
||||
|
||||
use crate::config::Config;
|
||||
use crate::config::ServerConfig;
|
||||
|
||||
use super::{
|
||||
paths::{PathGraph, PathIndex, PathQueue},
|
||||
|
|
@ -27,7 +27,7 @@ pub struct Base {
|
|||
}
|
||||
|
||||
impl Base {
|
||||
pub fn new(config: &Config, tab: Tab) -> Self {
|
||||
pub fn new(config: &ServerConfig, tab: Tab) -> Self {
|
||||
let tab = match tab {
|
||||
Tab::None => "",
|
||||
Tab::Index => "index",
|
||||
|
|
@ -53,7 +53,7 @@ impl Base {
|
|||
Link(format!("{base}{to}"))
|
||||
}
|
||||
|
||||
pub fn link_with_config<P: fmt::Display>(config: &Config, to: P) -> Link {
|
||||
pub fn link_with_config<P: fmt::Display>(config: &ServerConfig, to: P) -> Link {
|
||||
Self::link_with_base(&config.web_base, to)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use futures::TryStreamExt;
|
|||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
config::ServerConfig,
|
||||
server::{
|
||||
util,
|
||||
web::{
|
||||
|
|
@ -41,7 +41,7 @@ struct Page {
|
|||
|
||||
pub async fn get_commit_by_hash(
|
||||
path: PathCommitByHash,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
) -> somehow::Result<Response> {
|
||||
let base = Base::new(config, Tab::None);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use time::OffsetDateTime;
|
|||
use tracing::debug;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
config::ServerConfig,
|
||||
server::web::{
|
||||
base::{Base, Link, Tab},
|
||||
paths::{PathGraph, PathGraphData},
|
||||
|
|
@ -112,7 +112,7 @@ struct Page {
|
|||
|
||||
pub async fn get_graph(
|
||||
_path: PathGraph,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let metrics =
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use futures::TryStreamExt;
|
|||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
config::ServerConfig,
|
||||
server::web::{
|
||||
base::{Base, Tab},
|
||||
link::LinkCommit,
|
||||
|
|
@ -29,7 +29,7 @@ struct IndexTemplate {
|
|||
|
||||
pub async fn get_index(
|
||||
_path: PathIndex,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
let base = Base::new(config, Tab::Index);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ use futures::TryStreamExt;
|
|||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
config::ServerConfig,
|
||||
server::{
|
||||
util,
|
||||
web::{
|
||||
|
|
@ -161,7 +161,7 @@ struct PageInner {
|
|||
|
||||
pub async fn get_queue_inner(
|
||||
_path: PathQueueInner,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
State(workers): State<Arc<Mutex<Workers>>>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
|
|
@ -182,7 +182,7 @@ struct Page {
|
|||
|
||||
pub async fn get_queue(
|
||||
_path: PathQueue,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
State(workers): State<Arc<Mutex<Workers>>>,
|
||||
) -> somehow::Result<impl IntoResponse> {
|
||||
|
|
@ -210,7 +210,7 @@ struct PageDelete {
|
|||
|
||||
pub async fn get_queue_delete(
|
||||
path: PathQueueDelete,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
) -> somehow::Result<Response> {
|
||||
let base = Base::new(config, Tab::Queue);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use futures::TryStreamExt;
|
|||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
config::ServerConfig,
|
||||
server::{
|
||||
util,
|
||||
web::{
|
||||
|
|
@ -52,7 +52,7 @@ struct PageFinished {
|
|||
|
||||
async fn from_finished_run(
|
||||
id: &str,
|
||||
config: &'static Config,
|
||||
config: &'static ServerConfig,
|
||||
db: &SqlitePool,
|
||||
) -> somehow::Result<Option<Response>> {
|
||||
let Some(run) = sqlx::query!(
|
||||
|
|
@ -146,7 +146,7 @@ async fn from_finished_run(
|
|||
|
||||
pub async fn get_run_by_id(
|
||||
path: PathRunById,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
) -> somehow::Result<Response> {
|
||||
if let Some(response) = from_finished_run(&path.id, config, &db).await? {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use axum::{
|
|||
use sqlx::SqlitePool;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
config::ServerConfig,
|
||||
server::{
|
||||
util,
|
||||
web::{
|
||||
|
|
@ -58,7 +58,7 @@ async fn status(status: &WorkerStatus, db: &SqlitePool, base: &Base) -> somehow:
|
|||
|
||||
pub async fn get_worker_by_name(
|
||||
path: PathWorkerByName,
|
||||
State(config): State<&'static Config>,
|
||||
State(config): State<&'static ServerConfig>,
|
||||
State(db): State<SqlitePool>,
|
||||
State(workers): State<Arc<Mutex<Workers>>>,
|
||||
) -> somehow::Result<Response> {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use std::collections::{HashMap, HashSet};
|
|||
use time::OffsetDateTime;
|
||||
|
||||
use crate::{
|
||||
config::Config,
|
||||
config::ServerConfig,
|
||||
id,
|
||||
shared::{BenchMethod, Rfc3339Time, Run, UnfinishedRun, WorkerStatus},
|
||||
};
|
||||
|
|
@ -28,12 +28,12 @@ impl WorkerInfo {
|
|||
}
|
||||
|
||||
pub struct Workers {
|
||||
config: &'static Config,
|
||||
config: &'static ServerConfig,
|
||||
workers: HashMap<String, WorkerInfo>,
|
||||
}
|
||||
|
||||
impl Workers {
|
||||
pub fn new(config: &'static Config) -> Self {
|
||||
pub fn new(config: &'static ServerConfig) -> Self {
|
||||
Self {
|
||||
config,
|
||||
workers: HashMap::new(),
|
||||
|
|
@ -43,7 +43,7 @@ impl Workers {
|
|||
pub fn clean(&mut self) -> &mut Self {
|
||||
let now = OffsetDateTime::now_utc();
|
||||
self.workers
|
||||
.retain(|_, v| now <= v.last_seen + self.config.web_worker_timeout);
|
||||
.retain(|_, v| now <= v.last_seen + self.config.worker_timeout);
|
||||
self
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue