swarm daemons exit 0 when told to stop while still waiting for the store at startup
This commit is contained in:
parent
5dd39ba88c
commit
ae37c228b1
1 changed files with 133 additions and 32 deletions
|
|
@ -87,20 +87,28 @@ fn settings(var: Var<'_>, number: Number<'_>) -> Result<Settings> {
|
|||
})
|
||||
}
|
||||
|
||||
/// The queue connection, as the service's own OIDC client.
|
||||
async fn connect_queue(var: Var<'_>) -> Result<async_nats::Client> {
|
||||
/// The queue connection, as the service's own OIDC client. `None` when `stop`
|
||||
/// fired while the secret was still being waited for.
|
||||
async fn connect_queue(
|
||||
var: Var<'_>,
|
||||
stop: swarm_secret_client::Shutdown,
|
||||
) -> Result<Option<async_nats::Client>> {
|
||||
let client_id = var("OIDC_CLIENT_ID")?;
|
||||
let secret =
|
||||
swarm_secret_client::read_with_startup_retry("reading the queue client secret", || {
|
||||
client_secret(&client_id)
|
||||
})
|
||||
.await?;
|
||||
let Some(secret) = swarm_secret_client::read_with_startup_retry_or_stop(
|
||||
"reading the queue client secret",
|
||||
stop.clone(),
|
||||
|| client_secret(&client_id),
|
||||
)
|
||||
.await?
|
||||
else {
|
||||
return Ok(None);
|
||||
};
|
||||
let reread_id = client_id.clone();
|
||||
let secret = StoredSecret::new(client_id.clone(), secret, move || {
|
||||
let client_id = reread_id.clone();
|
||||
async move { client_secret(&client_id).await.map_err(Into::into) }
|
||||
});
|
||||
swarm_queue_client::connect(QueueConfig {
|
||||
let queue = swarm_queue_client::connect(QueueConfig {
|
||||
url: var("NATS_URL")?,
|
||||
token_endpoint: var("OIDC_TOKEN_ENDPOINT")?,
|
||||
client_id,
|
||||
|
|
@ -109,8 +117,8 @@ async fn connect_queue(var: Var<'_>) -> Result<async_nats::Client> {
|
|||
.ok()
|
||||
.map(PathBuf::from),
|
||||
})
|
||||
.await
|
||||
.map_err(Into::into)
|
||||
.await?;
|
||||
Ok(Some(queue))
|
||||
}
|
||||
|
||||
/// Removes expired transcripts from `cache` every [`PURGE_EVERY`], for as long as
|
||||
|
|
@ -155,7 +163,9 @@ async fn main() -> Result<()> {
|
|||
waiting,
|
||||
} = settings(&var, &number)?;
|
||||
let per_agent: Arc<Mutex<HashSet<String>>> = Arc::default();
|
||||
let queue = connect_queue(&var).await?;
|
||||
let Some(queue) = connect_queue(&var, stop.clone()).await? else {
|
||||
return Ok(());
|
||||
};
|
||||
swarm_queue_client::ready_when_connected(&health, &queue);
|
||||
let metrics = Arc::new(Metrics::from_env());
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue