Skip to content

Commit 2bb6a8a

Browse files
committed
set check frequency via config
1 parent 543c63e commit 2bb6a8a

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/lib.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct Config {
6464
struct EscalationConfig {
6565
enabled: bool,
6666
escalation_window: u64,
67+
check_frequency: u64,
6768
}
6869

6970
#[derive(StructOpt, Debug)]
@@ -110,6 +111,12 @@ pub async fn run() -> Result<()> {
110111
.unwrap_or(MIN_ESCALATION_WINDOW)
111112
.max(MIN_ESCALATION_WINDOW);
112113

114+
let check_frequency = config
115+
.escalation
116+
.as_ref()
117+
.map(|c| c.check_frequency)
118+
.unwrap_or(20);
119+
113120
if should_escalate && config.database.is_none() {
114121
return Err(anyhow!(
115122
"Escalations require a database configuration, which isn't provided"
@@ -133,7 +140,13 @@ pub async fn run() -> Result<()> {
133140
let (tx, mut recv) = unbounded_channel();
134141

135142
info!("Adding message processor to system registry");
136-
let proc = processor::Processor::new(opt_db, escalation_window, should_escalate, tx.clone());
143+
let proc = processor::Processor::new(
144+
opt_db,
145+
escalation_window,
146+
should_escalate,
147+
check_frequency,
148+
tx.clone(),
149+
);
137150
SystemRegistry::set(proc.start());
138151

139152
info!("Initializing Matrix client");

src/processor.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use std::time::Duration;
88
use tokio::sync::mpsc::UnboundedSender;
99
use tokio::sync::Mutex;
1010

11-
const CRON_JOB_INTERVAL: u64 = 5;
12-
1311
#[derive(Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
1412
pub struct AlertContext {
1513
pub id: AlertId,
@@ -91,6 +89,7 @@ pub struct Processor {
9189
should_escalate: bool,
9290
// Ensures that only one escalation task is running at the time.
9391
escalation_lock: Arc<Mutex<()>>,
92+
check_frequency: u64,
9493
shutdown_indicator: UnboundedSender<()>,
9594
}
9695

@@ -99,13 +98,15 @@ impl Processor {
9998
db: Option<Database>,
10099
escalation_window: u64,
101100
should_escalate: bool,
101+
check_frequency: u64,
102102
shutdown_indicator: UnboundedSender<()>,
103103
) -> Self {
104104
Processor {
105105
db: db.map(Arc::new),
106106
escalation_window,
107107
should_escalate,
108108
escalation_lock: Default::default(),
109+
check_frequency,
109110
shutdown_indicator,
110111
}
111112
}
@@ -159,7 +160,7 @@ impl Actor for Processor {
159160
let shutdown_indicator = self.shutdown_indicator.clone();
160161

161162
ctx.run_interval(
162-
Duration::from_secs(CRON_JOB_INTERVAL),
163+
Duration::from_secs(self.check_frequency),
163164
move |_proc, _ctx| {
164165
// Acquire new handles for async task.
165166
let db = Arc::clone(&db);

0 commit comments

Comments
 (0)