fix(scheduler): start a tick's scans together; the slots cap them (#61) (#823)
CI / Check (push) Skipped
CI / Agent integration (push) Skipped
CI / Detect Changes (push) Successful in 4s
CI / Deploy Dashboard (push) Skipped
CI / Deploy Docs (push) Skipped
CI / Deploy MCP (push) Skipped
CI / Deploy Agent (push) Successful in 5m54s

This commit was merged in pull request #823.
This commit is contained in:
sharang committed 2026-11-04 08:17:57 +00:00
1 parent 2523ecb018
commit 93b98965b3
1 file changed
+25 -15
+25 -15
View File
@@ -31,9 +31,15 @@ pub async fn start_scheduler(agent: &ComplianceAgent) -> Result<(), AgentError>
tenant_count = tenants.len(),
"Scheduled scan: tenants resolved"
);
for tenant_id in tenants {
scan_all_repos(&agent, &tenant_id).await;
}
// Every tenant and target at once: each scan waits for one of the
// `SCAN_CONCURRENCY` slots, so a slow repository holds one slot,
// not the whole tick (#61).
futures_util::future::join_all(
tenants
.iter()
.map(|tenant_id| scan_all_repos(&agent, tenant_id)),
)
.await;
})
})
.map_err(|e| AgentError::Scheduler(format!("Failed to create scan job: {e}")))?;
@@ -232,18 +238,22 @@ async fn scan_all_repos(agent: &ComplianceAgent, tenant_id: &str) {
let targets: Vec<_> = cursor.filter_map(|r| async { r.ok() }).collect().await;
for target in targets {
let target_id = target.id.map(|id| id.to_hex()).unwrap_or_default();
if let Err(e) = agent
.run_target_scan(tenant_id, &target_id, ScanTrigger::Scheduled)
.await
{
tracing::error!(
"Scheduled scan failed for {} (tenant '{tenant_id}'): {e}",
target.name
);
}
}
// Started together; the scan slots (`SCAN_CONCURRENCY`) decide how many
// run, and each scan's start jitter spreads them out.
futures_util::stream::iter(targets)
.for_each_concurrent(None, |target| async move {
let target_id = target.id.map(|id| id.to_hex()).unwrap_or_default();
if let Err(e) = agent
.run_target_scan(tenant_id, &target_id, ScanTrigger::Scheduled)
.await
{
tracing::error!(
"Scheduled scan failed for {} (tenant '{tenant_id}'): {e}",
target.name
);
}
})
.await;
}
async fn monitor_cves(agent: &ComplianceAgent, tenant_id: &str) {