broker: recv_batch(max) — drain a bursty inbox in one round-trip
This commit is contained in:
parent
96ffb0e39a
commit
77b89bf2c6
9 changed files with 354 additions and 11 deletions
|
|
@ -75,6 +75,11 @@ async fn serve(stream: UnixStream, coord: Arc<Coordinator>) -> Result<()> {
|
|||
/// seconds (clamped at MAX).
|
||||
const MANAGER_RECV_LONG_POLL_MAX: std::time::Duration = std::time::Duration::from_secs(180);
|
||||
|
||||
/// Same shape + rationale as `agent_server::RECV_BATCH_MAX`. Kept
|
||||
/// numerically aligned across surfaces so a tool description that
|
||||
/// quotes the cap stays accurate either way.
|
||||
const MANAGER_RECV_BATCH_MAX: u32 = 32;
|
||||
|
||||
fn manager_recv_timeout(wait_seconds: Option<u64>) -> std::time::Duration {
|
||||
match wait_seconds {
|
||||
Some(s) => std::time::Duration::from_secs(s).min(MANAGER_RECV_LONG_POLL_MAX),
|
||||
|
|
@ -149,6 +154,25 @@ async fn dispatch(req: &ManagerRequest, coord: &Arc<Coordinator>) -> ManagerResp
|
|||
message: format!("{e:#}"),
|
||||
},
|
||||
},
|
||||
ManagerRequest::RecvBatch { max } => {
|
||||
let cap = (*max).min(MANAGER_RECV_BATCH_MAX) as usize;
|
||||
match coord.broker.recv_batch(MANAGER_AGENT, cap) {
|
||||
Ok(deliveries) => ManagerResponse::Batch {
|
||||
messages: deliveries
|
||||
.into_iter()
|
||||
.map(|d| hive_sh4re::DeliveredMessage {
|
||||
from: d.message.from,
|
||||
body: d.message.body,
|
||||
id: d.id,
|
||||
redelivered: d.redelivered,
|
||||
})
|
||||
.collect(),
|
||||
},
|
||||
Err(e) => ManagerResponse::Err {
|
||||
message: format!("{e:#}"),
|
||||
},
|
||||
}
|
||||
}
|
||||
ManagerRequest::RequestSpawn { name, description } => {
|
||||
tracing::info!(%name, "manager: request_spawn");
|
||||
match coord.approvals.submit_kind(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue