Skip to content

Commit

Permalink
refactor(gateway): only ambulance ready projects (#1459)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chesedo authored Dec 2, 2023
1 parent 60138d9 commit c0c4e14
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
12 changes: 3 additions & 9 deletions gateway/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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();
Expand All @@ -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;
Expand Down
12 changes: 12 additions & 0 deletions gateway/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<impl ExactSizeIterator<Item = (ProjectName, AccountName)>, 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<impl ExactSizeIterator<Item = ProjectName>, Error> {
Expand Down

0 comments on commit c0c4e14

Please sign in to comment.