summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2024-02-20 09:36:01 +0200
committerLars Wirzenius <liw@liw.fi>2024-02-20 09:36:01 +0200
commit43b434faddfa9aecd0dc18c108b66428c25f132c (patch)
tree51556efa31847a719eec36de4c04846dd268ec8f
parent5d3aa44a92be306481612d8c8f10c85e9c9feefa (diff)
downloadradicle-ci-broker-43b434faddfa9aecd0dc18c108b66428c25f132c.tar.gz
feat: allow config file to set a status page update interval
Default is now 10 seconds. Signed-off-by: Lars Wirzenius <liw@liw.fi>
-rw-r--r--src/bin/ci-broker.rs9
-rw-r--r--src/config.rs8
2 files changed, 12 insertions, 5 deletions
diff --git a/src/bin/ci-broker.rs b/src/bin/ci-broker.rs
index d25cde6..26c506f 100644
--- a/src/bin/ci-broker.rs
+++ b/src/bin/ci-broker.rs
@@ -13,8 +13,6 @@ use radicle_ci_broker::{
msg::Request, status::Status,
};
-const STATUS_UPDATE_DELAY: Duration = Duration::from_millis(1000);
-
fn main() {
if let Err(e) = fallible_main() {
eprintln!("ERROR: {}", e);
@@ -77,7 +75,8 @@ fn fallible_main() -> Result<(), BrokerError> {
// Spawn a thread that updates the status page.
let mut status = Status::new(config.status_page().unwrap_or(Path::new("/dev/null")));
let s2 = status.clone();
- let _status_thread = spawn(move || status_updater(s2));
+ let interval = Duration::from_secs(config.status_page_update_interval());
+ let _status_thread = spawn(move || status_updater(s2, interval));
// This loop ends when there's an error, e.g., failure to read an
// event from the node.
@@ -92,11 +91,11 @@ fn fallible_main() -> Result<(), BrokerError> {
}
}
-fn status_updater(mut status: Status) {
+fn status_updater(mut status: Status, interval: Duration) {
loop {
if let Err(e) = status.write() {
eprintln!("ERROR: failed to update status page: {e}");
}
- sleep(STATUS_UPDATE_DELAY);
+ sleep(interval);
}
}
diff --git a/src/config.rs b/src/config.rs
index 13afefb..be4de35 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -9,12 +9,15 @@ use serde::{Deserialize, Serialize};
use crate::event::EventFilter;
+const DEFAULT_STATUS_PAGE_UPDATE_INTERVAL: u64 = 10;
+
#[derive(Debug, Serialize, Deserialize)]
pub struct Config {
pub default_adapter: String,
pub adapters: HashMap<String, Adapter>,
pub filters: Vec<EventFilter>,
pub status_page: Option<PathBuf>,
+ pub status_update_interval_seconds: Option<u64>,
}
impl Config {
@@ -31,6 +34,11 @@ impl Config {
pub fn status_page(&self) -> Option<&Path> {
self.status_page.as_deref()
}
+
+ pub fn status_page_update_interval(&self) -> u64 {
+ self.status_update_interval_seconds
+ .unwrap_or(DEFAULT_STATUS_PAGE_UPDATE_INTERVAL)
+ }
}
#[derive(Debug, Serialize, Deserialize)]