diff options
Diffstat (limited to 'makima/src/server/mod.rs')
| -rw-r--r-- | makima/src/server/mod.rs | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/makima/src/server/mod.rs b/makima/src/server/mod.rs index beee0e9..1c1ed6e 100644 --- a/makima/src/server/mod.rs +++ b/makima/src/server/mod.rs @@ -530,21 +530,34 @@ pub async fn run_server(state: SharedState, addr: &str) -> anyhow::Result<()> { // Spawn directive orchestrator - automates directive lifecycle let directive_pool = pool.clone(); let directive_state = state.clone(); + let directive_kick = state.directive_kick.clone(); tokio::spawn(async move { let mut orch = crate::orchestration::directive::DirectiveOrchestrator::new( directive_pool, directive_state, ); let mut interval = tokio::time::interval(std::time::Duration::from_secs(15)); + // Skip the immediate-fire that `interval` does on creation so the + // first tick still waits one period after startup. + interval.tick().await; loop { - interval.tick().await; + tokio::select! { + _ = interval.tick() => {} + _ = directive_kick.notified() => { + // A handler nudged us — run a tick right away, but + // keep the interval running so we still poll on the + // regular cadence in addition to the kick. + } + } if let Err(e) = orch.tick().await { tracing::warn!(error = %e, "Directive orchestrator tick failed"); } } }); - tracing::info!("Directive orchestrator started (interval: 15s)"); + tracing::info!( + "Directive orchestrator started (interval: 15s, also kicked on goal updates)" + ); } let app = make_router(state); |
