Skip to content

Commit 884ba3d

Browse files
Tim-Zhangmxpv
authored andcommitted
shim: re-impl Events trait for async RemotePublisher
Fixes: https://github.com/containerd/rust-extensions/pull/318/files#r2212454388 Signed-off-by: Tim Zhang <[email protected]>
1 parent 4ae8331 commit 884ba3d

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

crates/shim/src/asynchronous/publisher.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616

1717
use std::os::unix::io::RawFd;
1818

19+
use async_trait::async_trait;
1920
use containerd_shim_protos::{
20-
api::Envelope,
21+
api::{Empty, Envelope},
2122
protobuf::MessageDyn,
2223
shim::events,
23-
shim_async::{Client, EventsClient},
24+
shim_async::{Client, Events, EventsClient},
2425
ttrpc,
25-
ttrpc::context::Context,
26+
ttrpc::{context::Context, r#async::TtrpcContext},
2627
};
2728
use log::{debug, error, warn};
2829
use tokio::sync::mpsc;
@@ -169,6 +170,29 @@ impl RemotePublisher {
169170
}
170171
}
171172

173+
#[async_trait]
174+
impl Events for RemotePublisher {
175+
async fn forward(
176+
&self,
177+
_ctx: &TtrpcContext,
178+
req: events::ForwardRequest,
179+
) -> ttrpc::Result<Empty> {
180+
let item = Item {
181+
ev: req.envelope().clone(),
182+
ctx: Context::default(),
183+
count: 0,
184+
};
185+
186+
//if channel is full and send fail ,release it after 3 seconds
187+
self.sender
188+
.send_timeout(item, tokio::time::Duration::from_secs(3))
189+
.await
190+
.map_err(|e| error::Error::Ttrpc(ttrpc::error::Error::Others(e.to_string())))?;
191+
192+
Ok(Empty::default())
193+
}
194+
}
195+
172196
#[cfg(test)]
173197
mod tests {
174198
use std::{

0 commit comments

Comments
 (0)