swarm daemons: opt-in /healthz and /readyz listener, and /readyz on the controller
This commit is contained in:
parent
377bc1d5df
commit
c21b158884
1 changed files with 787 additions and 26 deletions
|
|
@ -113,6 +113,20 @@ async fn connect_queue(var: Var<'_>) -> Result<async_nats::Client> {
|
|||
.map_err(Into::into)
|
||||
}
|
||||
|
||||
/// Removes expired transcripts from `cache` every [`PURGE_EVERY`], for as long as
|
||||
/// the process runs.
|
||||
fn spawn_purge(cache: Cache) {
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
let removed = cache.purge().await;
|
||||
if removed > 0 {
|
||||
tracing::info!(removed, "removed expired transcripts");
|
||||
}
|
||||
tokio::time::sleep(PURGE_EVERY).await;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let stop = swarm_secret_client::shutdown_signal();
|
||||
|
|
@ -129,6 +143,11 @@ async fn main() -> Result<()> {
|
|||
Err(_) => Ok(default),
|
||||
}
|
||||
};
|
||||
let health = swarm_secret_client::health::Health::from_env(
|
||||
&format!("{PREFIX}_HEALTH_ADDR"),
|
||||
stop.clone(),
|
||||
)
|
||||
.await?;
|
||||
|
||||
let Settings {
|
||||
service,
|
||||
|
|
@ -137,23 +156,18 @@ async fn main() -> Result<()> {
|
|||
} = settings(&var, &number)?;
|
||||
let per_agent: Arc<Mutex<HashSet<String>>> = Arc::default();
|
||||
let queue = connect_queue(&var).await?;
|
||||
swarm_queue_client::ready_when_connected(&health, &queue);
|
||||
let metrics = Arc::new(Metrics::from_env());
|
||||
|
||||
tokio::spawn(async move {
|
||||
loop {
|
||||
let removed = cache.purge().await;
|
||||
if removed > 0 {
|
||||
tracing::info!(removed, "removed expired transcripts");
|
||||
}
|
||||
tokio::time::sleep(PURGE_EVERY).await;
|
||||
}
|
||||
});
|
||||
spawn_purge(cache);
|
||||
|
||||
let mut requests = queue
|
||||
.queue_subscribe(subject_wildcard(), QUEUE_GROUP.to_owned())
|
||||
.await
|
||||
.context("subscribing to the request subject")?
|
||||
.take_until(stop.clone());
|
||||
let mut requests = health.beating(
|
||||
queue
|
||||
.queue_subscribe(subject_wildcard(), QUEUE_GROUP.to_owned())
|
||||
.await
|
||||
.context("subscribing to the request subject")?
|
||||
.take_until(stop.clone()),
|
||||
);
|
||||
tracing::info!(
|
||||
subject = subject_wildcard(),
|
||||
"swarm-stt: answering requests"
|
||||
|
|
|
|||
Loading…
Reference in a new issue