Update repo repeatedly
This commit is contained in:
parent
0a555dd9b4
commit
980e84b0f6
5 changed files with 72 additions and 24 deletions
34
Cargo.lock
generated
34
Cargo.lock
generated
|
|
@ -328,12 +328,6 @@ version = "1.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
|
checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "bytesize"
|
|
||||||
version = "1.2.0"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "38fcc2979eff34a4b84e1cf9a1e3da42a7d44b3b690a40cdcb23e3d556cfb2e5"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "cc"
|
name = "cc"
|
||||||
version = "1.0.81"
|
version = "1.0.81"
|
||||||
|
|
@ -1029,7 +1023,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "882695cccf38da4c3cc7ee687bdb412cf25e37932d7f8f2c306112ea712449f1"
|
checksum = "882695cccf38da4c3cc7ee687bdb412cf25e37932d7f8f2c306112ea712449f1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytes",
|
"bytes",
|
||||||
"bytesize",
|
|
||||||
"crc32fast",
|
"crc32fast",
|
||||||
"crossbeam-channel",
|
"crossbeam-channel",
|
||||||
"flate2",
|
"flate2",
|
||||||
|
|
@ -1585,12 +1578,6 @@ version = "1.0.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
|
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "human_format"
|
|
||||||
version = "1.0.3"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "86cce260d758a9aa3d7c4b99d55c815a540f8a37514ba6046ab6be402a157cb0"
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "humansize"
|
name = "humansize"
|
||||||
version = "2.1.3"
|
version = "2.1.3"
|
||||||
|
|
@ -1600,6 +1587,22 @@ dependencies = [
|
||||||
"libm",
|
"libm",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "humantime"
|
||||||
|
version = "2.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "humantime-serde"
|
||||||
|
version = "1.1.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "57a3db5ea5923d99402c94e9feb261dc5ee9b4efa158b0315f788cf549cc200c"
|
||||||
|
dependencies = [
|
||||||
|
"humantime",
|
||||||
|
"serde",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hyper"
|
name = "hyper"
|
||||||
version = "0.14.27"
|
version = "0.14.27"
|
||||||
|
|
@ -2080,10 +2083,6 @@ name = "prodash"
|
||||||
version = "25.0.1"
|
version = "25.0.1"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "c236e70b7f9b9ea00d33c69f63ec1ae6e9ae96118923cd37bd4e9c7396f0b107"
|
checksum = "c236e70b7f9b9ea00d33c69f63ec1ae6e9ae96118923cd37bd4e9c7396f0b107"
|
||||||
dependencies = [
|
|
||||||
"bytesize",
|
|
||||||
"human_format",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "quote"
|
name = "quote"
|
||||||
|
|
@ -2733,6 +2732,7 @@ dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"directories",
|
"directories",
|
||||||
"gix",
|
"gix",
|
||||||
|
"humantime-serde",
|
||||||
"mime_guess",
|
"mime_guess",
|
||||||
"rust-embed",
|
"rust-embed",
|
||||||
"serde",
|
"serde",
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ askama_axum = "0.3.0"
|
||||||
axum = { version = "0.6.19", features = ["macros"] }
|
axum = { version = "0.6.19", features = ["macros"] }
|
||||||
clap = { version = "4.3.19", features = ["derive", "deprecated"] }
|
clap = { version = "4.3.19", features = ["derive", "deprecated"] }
|
||||||
directories = "5.0.1"
|
directories = "5.0.1"
|
||||||
gix = "0.51.0"
|
humantime-serde = "1.1.1"
|
||||||
mime_guess = "2.0.4"
|
mime_guess = "2.0.4"
|
||||||
rust-embed = "6.8.1"
|
rust-embed = "6.8.1"
|
||||||
serde = { version = "1.0.181", features = ["derive"] }
|
serde = { version = "1.0.181", features = ["derive"] }
|
||||||
|
|
@ -20,6 +20,11 @@ toml = "0.7.6"
|
||||||
tracing = "0.1.37"
|
tracing = "0.1.37"
|
||||||
tracing-subscriber = "0.3.17"
|
tracing-subscriber = "0.3.17"
|
||||||
|
|
||||||
|
[dependencies.gix]
|
||||||
|
version = "0.51.0"
|
||||||
|
default-features = false
|
||||||
|
features = ["max-performance-safe", "extras"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
vergen = { version = "8.2.4", features = ["git", "gitcl"] }
|
vergen = { version = "8.2.4", features = ["git", "gitcl"] }
|
||||||
walkdir = "2.3.3"
|
walkdir = "2.3.3"
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,45 @@
|
||||||
//! Configuration from a file.
|
//! Configuration from a file.
|
||||||
|
|
||||||
use std::{fs, io::ErrorKind, path::Path};
|
use std::{fs, io::ErrorKind, path::Path, time::Duration};
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tracing::info;
|
use tracing::{debug, info};
|
||||||
|
|
||||||
#[derive(Debug, Default, Deserialize)]
|
mod default {
|
||||||
pub struct Config {}
|
use std::time::Duration;
|
||||||
|
|
||||||
|
pub fn repo_update_delay() -> Duration {
|
||||||
|
Duration::from_secs(60)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
|
pub struct Config {
|
||||||
|
#[serde(default = "default::repo_update_delay", with = "humantime_serde")]
|
||||||
|
pub repo_update_delay: Duration,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Default for Config {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
repo_update_delay: default::repo_update_delay(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn load(path: &Path) -> anyhow::Result<Self> {
|
pub fn load(path: &Path) -> anyhow::Result<Self> {
|
||||||
info!(path = %path.display(), "Loading config");
|
info!(path = %path.display(), "Loading config");
|
||||||
Ok(match fs::read_to_string(path) {
|
let config = match fs::read_to_string(path) {
|
||||||
Ok(str) => toml::from_str(&str)?,
|
Ok(str) => toml::from_str(&str)?,
|
||||||
Err(e) if e.kind() == ErrorKind::NotFound => {
|
Err(e) if e.kind() == ErrorKind::NotFound => {
|
||||||
info!("No config file found, using default config");
|
info!("No config file found, using default config");
|
||||||
Self::default()
|
Self::default()
|
||||||
}
|
}
|
||||||
Err(e) => Err(e)?,
|
Err(e) => Err(e)?,
|
||||||
})
|
};
|
||||||
|
|
||||||
|
debug!("Loaded config:\n{config:#?}");
|
||||||
|
Ok(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
mod config;
|
mod config;
|
||||||
mod state;
|
mod state;
|
||||||
mod r#static;
|
mod r#static;
|
||||||
|
mod update;
|
||||||
|
|
||||||
use std::{io, path::PathBuf};
|
use std::{io, path::PathBuf};
|
||||||
|
|
||||||
|
|
@ -115,6 +116,7 @@ async fn run() -> anyhow::Result<()> {
|
||||||
select! {
|
select! {
|
||||||
_ = wait_for_signal() => {},
|
_ = wait_for_signal() => {},
|
||||||
_ = server.serve(app) => {},
|
_ = server.serve(app) => {},
|
||||||
|
_ = update::repeatedly(state.clone()) => {},
|
||||||
}
|
}
|
||||||
|
|
||||||
state.shut_down().await;
|
state.shut_down().await;
|
||||||
|
|
|
||||||
19
src/update.rs
Normal file
19
src/update.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
//! Repeatedly update the db from the repo.
|
||||||
|
|
||||||
|
use tracing::{warn, debug};
|
||||||
|
|
||||||
|
use crate::state::AppState;
|
||||||
|
|
||||||
|
async fn update_repo(state: &AppState) -> anyhow::Result<()> {
|
||||||
|
debug!("Updating repo");
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn repeatedly(state: AppState) {
|
||||||
|
loop {
|
||||||
|
if let Err(e) = update_repo(&state).await {
|
||||||
|
warn!("Error while updating repo: {e:?}");
|
||||||
|
}
|
||||||
|
tokio::time::sleep(state.config.repo_update_delay).await;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue