Radish alpha
r
Radicle CI broker
Radicle
Git (anonymous pull)
Log in to clone via SSH
feat: allow config file to set a status page update interval
Lars Wirzenius committed 2 years ago
commit 43b434faddfa9aecd0dc18c108b66428c25f132c
parent 5d3aa44a92be306481612d8c8f10c85e9c9feefa
2 files changed +12 -5
modified 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);
    }
}
modified 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)]