mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-05-01 21:24:36 +00:00
runtime-rs: refine implementation of TaskService
Refine implementation of TaskService, making handler_message() as a method. Fixes: #7479 Signed-off-by: Jiang Liu <gerry@linux.alibaba.com>
This commit is contained in:
parent
458e1bc712
commit
62e328ca5c
@ -24,31 +24,31 @@ impl TaskService {
|
|||||||
pub(crate) fn new(handler: Arc<RuntimeHandlerManager>) -> Self {
|
pub(crate) fn new(handler: Arc<RuntimeHandlerManager>) -> Self {
|
||||||
Self { handler }
|
Self { handler }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
async fn handler_message<TtrpcReq, TtrpcResp>(
|
async fn handler_message<TtrpcReq, TtrpcResp>(
|
||||||
s: &RuntimeHandlerManager,
|
&self,
|
||||||
ctx: &TtrpcContext,
|
ctx: &TtrpcContext,
|
||||||
req: TtrpcReq,
|
req: TtrpcReq,
|
||||||
) -> ttrpc::Result<TtrpcResp>
|
) -> ttrpc::Result<TtrpcResp>
|
||||||
where
|
where
|
||||||
Request: TryFrom<TtrpcReq>,
|
Request: TryFrom<TtrpcReq>,
|
||||||
<Request as TryFrom<TtrpcReq>>::Error: std::fmt::Debug,
|
<Request as TryFrom<TtrpcReq>>::Error: std::fmt::Debug,
|
||||||
TtrpcResp: TryFrom<Response>,
|
TtrpcResp: TryFrom<Response>,
|
||||||
<TtrpcResp as TryFrom<Response>>::Error: std::fmt::Debug,
|
<TtrpcResp as TryFrom<Response>>::Error: std::fmt::Debug,
|
||||||
{
|
{
|
||||||
let r = req
|
let r = req.try_into().map_err(|err| {
|
||||||
.try_into()
|
ttrpc::Error::Others(format!("failed to translate from shim {:?}", err))
|
||||||
.map_err(|err| ttrpc::Error::Others(format!("failed to translate from shim {:?}", err)))?;
|
})?;
|
||||||
let logger = sl!().new(o!("stream id" => ctx.mh.stream_id));
|
let logger = sl!().new(o!("stream id" => ctx.mh.stream_id));
|
||||||
debug!(logger, "====> task service {:?}", &r);
|
debug!(logger, "====> task service {:?}", &r);
|
||||||
let resp = s
|
let resp =
|
||||||
.handler_message(r)
|
self.handler.handler_message(r).await.map_err(|err| {
|
||||||
.await
|
ttrpc::Error::Others(format!("failed to handler message {:?}", err))
|
||||||
.map_err(|err| ttrpc::Error::Others(format!("failed to handler message {:?}", err)))?;
|
})?;
|
||||||
debug!(logger, "<==== task service {:?}", &resp);
|
debug!(logger, "<==== task service {:?}", &resp);
|
||||||
resp.try_into()
|
resp.try_into()
|
||||||
.map_err(|err| ttrpc::Error::Others(format!("failed to translate to shim {:?}", err)))
|
.map_err(|err| ttrpc::Error::Others(format!("failed to translate to shim {:?}", err)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! impl_service {
|
macro_rules! impl_service {
|
||||||
@ -56,7 +56,7 @@ macro_rules! impl_service {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl shim_async::Task for TaskService {
|
impl shim_async::Task for TaskService {
|
||||||
$(async fn $name(&self, ctx: &TtrpcContext, req: $req) -> ttrpc::Result<$resp> {
|
$(async fn $name(&self, ctx: &TtrpcContext, req: $req) -> ttrpc::Result<$resp> {
|
||||||
handler_message(&self.handler, ctx, req).await
|
self.handler_message(ctx, req).await
|
||||||
})*
|
})*
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user