Watch
0
0
Fork
You've already forked hyperhive
0

queue consumers: stop taking messages on sigterm and exit 0

This commit is contained in:
atlas 2026-11-18 03:28:12 +01:00 • committed by mara
commit a8775f1a7a

View file

@ -100,6 +100,7 @@ impl login::CredentialSink for AgentLeaf {
#[tokio::main]
async fn main() -> Result<()> {
let stop = swarm_secret_client::shutdown_signal();
hive_log::init();
swarm_secret_client::install_crypto_provider();
let var = |name: &str| {
@ -138,9 +139,11 @@ async fn main() -> Result<()> {
let mut requests = queue
.subscribe(SUBJECT)
.await
.with_context(|| format!("subscribing to {SUBJECT}"))?;
.with_context(|| format!("subscribing to {SUBJECT}"))?
.take_until(stop.clone());
tracing::info!(subject = SUBJECT, "claude login minter: awaiting logins");
let mut in_flight = swarm_secret_client::InFlight::new();
while let Some(msg) = requests.next().await {
let Some(reply_to) = msg.reply.clone() else {
tracing::warn!("a login step arrived with no reply subject; dropping it");
@ -149,7 +152,7 @@ async fn main() -> Result<()> {
let queue = queue.clone();
let logins = Arc::clone(&logins);
let metrics = Arc::clone(&metrics);
tokio::spawn(async move {
in_flight.spawn(async move {
let reply = handle(&msg.payload, &logins, &metrics).await;
match serde_json::to_vec(&reply) {
Ok(body) => {
@ -161,7 +164,11 @@ async fn main() -> Result<()> {
}
});
}
bail!("the subscription to {SUBJECT} ended")
in_flight.drain().await;
if stop.peek().is_none() {
bail!("the subscription to {SUBJECT} ended");
}
Ok(())
}
/// Answer one step and count it.