wowlab_sentinel/cron/
queue_depth.rs1use std::sync::atomic::Ordering;
2
3use async_trait::async_trait;
4
5use crate::{cron::CronJob, state::ServerState};
6
7#[derive(Debug)]
8pub(super) struct QueueDepthJob {
9 schedule: String,
10}
11
12impl QueueDepthJob {
13 pub(super) fn new(schedule: &str) -> Self {
14 Self {
15 schedule: schedule.to_string(),
16 }
17 }
18}
19
20#[async_trait]
21impl CronJob for QueueDepthJob {
22 fn name(&self) -> &'static str {
23 "queue_depth"
24 }
25
26 fn schedule(&self) -> &str {
27 &self.schedule
28 }
29
30 async fn run(&self, state: &ServerState) {
31 let depth = compute_pending_depth(state).await;
32 #[expect(
33 clippy::cast_precision_loss,
34 reason = "metrics gauges accept f64 and queue depth is operationally far below exact-integer limits"
35 )]
36 let depth_sample = depth as f64;
37
38 metrics::gauge!(crate::telemetry::CHUNKS_PENDING).set(depth_sample);
39 state.runtime.pending_chunks.store(depth, Ordering::Relaxed);
40 }
41}
42
43async fn compute_pending_depth(state: &ServerState) -> i64 {
44 let runtime = state.runtime.jobs.read().await;
45
46 crate::scheduler::backlog::pending_claim_count(&runtime)
47}