upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/grasp-audit/src/bin
diff options
context:
space:
mode:
authorDanConwayDev <DanConwayDev@protonmail.com>2026-02-25 13:55:52 +0000
committerDanConwayDev <DanConwayDev@protonmail.com>2026-02-25 13:55:52 +0000
commit6007647e37344bcc3e8ade6500ed5dbb11d302e0 (patch)
tree0e6eb3d1405361a0539ac65ba31bfefdd2495ec3 /grasp-audit/src/bin
parent680b4f4ec7d9cc5535b348bdc8604cf43d3fc80b (diff)
add overall probe timeout of min(20s, watch_interval) to prevent overlapping runs
Diffstat (limited to 'grasp-audit/src/bin')
-rw-r--r--grasp-audit/src/bin/grasp-audit.rs36
1 files changed, 31 insertions, 5 deletions
diff --git a/grasp-audit/src/bin/grasp-audit.rs b/grasp-audit/src/bin/grasp-audit.rs
index 3d5b107..f56fc44 100644
--- a/grasp-audit/src/bin/grasp-audit.rs
+++ b/grasp-audit/src/bin/grasp-audit.rs
@@ -102,15 +102,31 @@ async fn main() -> Result<()> {
102 None 102 None
103 }; 103 };
104 104
105 // Overall probe timeout: min(20s, watch_interval) to prevent
106 // overlapping runs under --watch or cron scheduling.
107 let overall_secs = match watch {
108 Some(interval) => interval.min(20),
109 None => 20,
110 };
111
105 if let Some(interval) = watch { 112 if let Some(interval) = watch {
106 let mut run = 1u64; 113 let mut run = 1u64;
107 loop { 114 loop {
108 if !json { 115 if !json {
109 println!("\n[Run {}]", run); 116 println!("\n[Run {}]", run);
110 } 117 }
111 let report = 118 let start = std::time::Instant::now();
112 grasp_audit::probe::run_probe(&relay, keys.clone(), read_only, timeout) 119 let report = tokio::time::timeout(
113 .await; 120 Duration::from_secs(overall_secs),
121 grasp_audit::probe::run_probe(&relay, keys.clone(), read_only, timeout),
122 )
123 .await
124 .unwrap_or_else(|_| {
125 grasp_audit::probe::ProbeReport::overall_timeout(
126 &relay,
127 start.elapsed().as_millis() as u64,
128 )
129 });
114 if json { 130 if json {
115 report.print_json(); 131 report.print_json();
116 } else { 132 } else {
@@ -120,8 +136,18 @@ async fn main() -> Result<()> {
120 tokio::time::sleep(Duration::from_secs(interval)).await; 136 tokio::time::sleep(Duration::from_secs(interval)).await;
121 } 137 }
122 } else { 138 } else {
123 let report = 139 let start = std::time::Instant::now();
124 grasp_audit::probe::run_probe(&relay, keys, read_only, timeout).await; 140 let report = tokio::time::timeout(
141 Duration::from_secs(overall_secs),
142 grasp_audit::probe::run_probe(&relay, keys, read_only, timeout),
143 )
144 .await
145 .unwrap_or_else(|_| {
146 grasp_audit::probe::ProbeReport::overall_timeout(
147 &relay,
148 start.elapsed().as_millis() as u64,
149 )
150 });
125 if json { 151 if json {
126 report.print_json(); 152 report.print_json();
127 } else { 153 } else {