Remove unnecessary dependencies in tonic-health (#502)
* remove dependency on bytes * remove dependency on async-stream
This commit is contained in:
@@ -18,10 +18,8 @@ default = ["transport"]
|
|||||||
transport = ["tonic/transport"]
|
transport = ["tonic/transport"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-stream = "0.2"
|
|
||||||
tokio = { version = "0.2", features = ["sync", "stream"] }
|
tokio = { version = "0.2", features = ["sync", "stream"] }
|
||||||
tonic = { version = "0.3", path = "../tonic", features = ["codegen", "prost"] }
|
tonic = { version = "0.3", path = "../tonic", features = ["codegen", "prost"] }
|
||||||
bytes = "0.5"
|
|
||||||
prost = "0.6"
|
prost = "0.6"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::ServingStatus;
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use tokio::stream::Stream;
|
use tokio::stream::{Stream, StreamExt};
|
||||||
use tokio::sync::{watch, RwLock};
|
use tokio::sync::{watch, RwLock};
|
||||||
#[cfg(feature = "transport")]
|
#[cfg(feature = "transport")]
|
||||||
use tonic::transport::NamedService;
|
use tonic::transport::NamedService;
|
||||||
@@ -148,18 +148,15 @@ impl Health for HealthService {
|
|||||||
request: Request<HealthCheckRequest>,
|
request: Request<HealthCheckRequest>,
|
||||||
) -> Result<Response<Self::WatchStream>, Status> {
|
) -> Result<Response<Self::WatchStream>, Status> {
|
||||||
let service_name = request.get_ref().service.as_str();
|
let service_name = request.get_ref().service.as_str();
|
||||||
let mut status_rx = match self.statuses.read().await.get(service_name) {
|
let status_rx = match self.statuses.read().await.get(service_name) {
|
||||||
None => return Err(Status::not_found("service not registered")),
|
None => return Err(Status::not_found("service not registered")),
|
||||||
Some(pair) => pair.1.clone(),
|
Some(pair) => pair.1.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let output = async_stream::try_stream! {
|
let output = status_rx.map(|status| {
|
||||||
while let Some(status) = status_rx.recv().await {
|
let status = crate::proto::health_check_response::ServingStatus::from(status) as i32;
|
||||||
yield HealthCheckResponse{
|
Ok(HealthCheckResponse { status })
|
||||||
status: crate::proto::health_check_response::ServingStatus::from(status) as i32,
|
});
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Ok(Response::new(Box::pin(output) as Self::WatchStream))
|
Ok(Response::new(Box::pin(output) as Self::WatchStream))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user