From 33f36adf3f4f32dbcd1f099e6b9b4824972921d2 Mon Sep 17 00:00:00 2001 From: Neshura Date: Thu, 28 Dec 2023 22:20:12 +0100 Subject: [PATCH] Configurable Update Interval. Closes #29 --- src/main.rs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index 259d2f9..cd0c15b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ /*use cloudflare_old::{Instance, CloudflareDnsType};*/ use reqwest::blocking::get; -use std::{thread::{sleep}}; +use std::{env, thread::{sleep}}; use std::error::Error; use std::net::{Ipv4Addr, Ipv6Addr}; use std::str::FromStr; @@ -248,9 +248,28 @@ fn main() { Err(e) => panic!("{}", e) }; + let reload_interval = match env::var("RELOAD_INTERVAL_SECONDS") { + Ok(interval_string) => i64::from_str(&interval_string).unwrap_or_else(|e| { + let warn_msg = format!("Expected integer number, got '{interval_string}'. Defaulting to 60"); + match connected_to_journal() { + true => warn!("[WARN] {warn_msg}"), + false => println!("[WARN] {warn_msg}"), + }; + 60 + }), + Err(_) => { + let warn_msg = "Reload interval env not set, defaulting to 60"; + match connected_to_journal() { + true => warn!("[WARN] {warn_msg}"), + false => println!("[WARN] {warn_msg}"), + } + 60 + }, + }; + loop { now = Utc::now(); - if now >= start + Duration::seconds(10) { // DEBUG was 60 + if now >= start + Duration::seconds(reload_interval) { // DEBUG was 60 start = now; match InterfaceConfig::load() {