feat(#2300): recv reports remaining inbox depth so agents know how many messages are left
This commit is contained in:
parent
371f888640
commit
493face93c
6 changed files with 153 additions and 52 deletions
|
|
@ -309,18 +309,26 @@ async fn handle_recv(
|
|||
.recv_blocking_batch(agent, recv_timeout(wait_seconds), cap)
|
||||
.await
|
||||
{
|
||||
Ok(deliveries) => hive_sh4re::Response::Messages {
|
||||
messages: deliveries
|
||||
.into_iter()
|
||||
.map(|d| hive_sh4re::DeliveredMessage {
|
||||
from: d.message.from,
|
||||
body: d.message.body,
|
||||
id: d.id,
|
||||
redelivered: d.redelivered,
|
||||
in_reply_to: d.message.in_reply_to,
|
||||
})
|
||||
.collect(),
|
||||
},
|
||||
Ok(deliveries) => {
|
||||
// `recv_batch` stamps `delivered_at` on every popped row, so a
|
||||
// `count_pending` here excludes the just-popped batch and reports
|
||||
// exactly how many still-pending messages remain to drain. A count
|
||||
// error is non-fatal — fall back to 0 rather than fail the recv.
|
||||
let remaining = coord.broker.count_pending(agent).unwrap_or(0);
|
||||
hive_sh4re::Response::Messages {
|
||||
messages: deliveries
|
||||
.into_iter()
|
||||
.map(|d| hive_sh4re::DeliveredMessage {
|
||||
from: d.message.from,
|
||||
body: d.message.body,
|
||||
id: d.id,
|
||||
redelivered: d.redelivered,
|
||||
in_reply_to: d.message.in_reply_to,
|
||||
})
|
||||
.collect(),
|
||||
remaining,
|
||||
}
|
||||
}
|
||||
Err(e) => hive_sh4re::Response::Err {
|
||||
message: format!("{e:#}"),
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue