From c0c4e14c4043252c6ce350933ef911a9c84e170c Mon Sep 17 00:00:00 2001 From: Pieter Date: Sat, 2 Dec 2023 14:53:15 +0000 Subject: [PATCH] refactor(gateway): only ambulance ready projects (#1459) We just do nothing for all the other dead end states anyway. And for the intermediate states, the tasks that started them will drive them to completion anyway. --- gateway/src/main.rs | 12 +++--------- gateway/src/service.rs | 12 ++++++++++++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/gateway/src/main.rs b/gateway/src/main.rs index 0de8598f7..89a7e7bb0 100644 --- a/gateway/src/main.rs +++ b/gateway/src/main.rs @@ -20,7 +20,7 @@ use std::path::PathBuf; use std::str::FromStr; use std::sync::Arc; use std::time::Duration; -use tracing::{debug, error, field, info, info_span, trace, warn, Instrument, Span}; +use tracing::{debug, error, info, info_span, trace, warn, Instrument}; #[tokio::main(flavor = "multi_thread")] async fn main() -> io::Result<()> { @@ -98,11 +98,10 @@ async fn start(db: SqlitePool, fs: PathBuf, args: StartArgs) -> io::Result<()> { continue; } - if let Ok(projects) = gateway.iter_projects().await { + if let Ok(projects) = gateway.iter_projects_ready().await { let span = info_span!( "running health checks", - healthcheck.num_projects = projects.len(), - healthcheck.active_projects = field::Empty, + healthcheck.active_projects = projects.len(), ); let gateway = gateway.clone(); @@ -117,11 +116,6 @@ async fn start(db: SqlitePool, fs: PathBuf, args: StartArgs) -> io::Result<()> { handle.await } } - - let active_projects = - gateway.count_ready_projects().await.unwrap_or_default(); - let span = Span::current(); - span.record("healthcheck.active_projects", active_projects); } .instrument(span) .await; diff --git a/gateway/src/service.rs b/gateway/src/service.rs index 70f84a6cd..0c93664b1 100644 --- a/gateway/src/service.rs +++ b/gateway/src/service.rs @@ -334,6 +334,18 @@ impl GatewayService { Ok(iter) } + /// Only get an iterator for the projects that are ready + pub async fn iter_projects_ready( + &self, + ) -> Result, Error> { + let iter = query("SELECT project_name, account_name FROM projects, JSON_EACH(project_state) WHERE key = 'ready'") + .fetch_all(&self.db) + .await? + .into_iter() + .map(|row| (row.get("project_name"), row.get("account_name"))); + Ok(iter) + } + pub async fn iter_cch_projects( &self, ) -> Result, Error> {