Skip to content

Commit 1955c6c

Browse files
committed
Merge branch 'impl-health-server' of github.com:busyjay/grpc-rs into impl-health-server
Signed-off-by: Jay Lee <[email protected]>
2 parents 7d69878 + ab5b586 commit 1955c6c

File tree

8 files changed

+713
-104
lines changed

8 files changed

+713
-104
lines changed

health/Cargo.toml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,13 @@ readme = "README.md"
1414

1515
[features]
1616
default = ["protobuf-codec", "use-bindgen"]
17-
protobuf-codec = ["grpcio/protobuf-codec", "protobuf", "protobuf-build/grpcio-protobuf-codec"]
18-
prost-codec = ["grpcio/prost-codec", "prost", "protobuf-build/grpcio-prost-codec", "lazy_static"]
17+
protobuf-codec = ["grpcio/protobuf-codec", "protobuf"]
18+
prost-codec = ["grpcio/prost-codec", "prost"]
1919
use-bindgen = ["grpcio/use-bindgen"]
2020

2121
[dependencies]
2222
futures = "0.3"
2323
grpcio = { path = "..", features = ["secure"], version = "0.8.0", default-features = false }
2424
prost = { version = "0.7", optional = true }
2525
protobuf = { version = "2", optional = true }
26-
lazy_static = { version = "1.3", optional = true }
2726
log = "0.4"
28-
29-
[build-dependencies]
30-
protobuf-build = { version = "0.12", default-features = false }

health/build.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

health/proto/grpc/health/v1/health.proto

Lines changed: 0 additions & 63 deletions
This file was deleted.

health/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@
3434
pub mod proto;
3535
mod service;
3636

37-
pub use self::proto::{create_health, HealthClient};
37+
pub use self::proto::{create_health, HealthClient, ServingStatus};
3838
pub use self::service::HealthService;

health/src/proto.rs

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,20 @@
22

33
#[cfg(feature = "prost-codec")]
44
mod reexports {
5-
include!(concat!(env!("OUT_DIR"), "/mod.rs"));
5+
include!("proto/grpc.health.v1.rs");
66

7-
pub use self::grpc::health::v1::*;
87
pub use self::health_check_response::ServingStatus;
98
}
109

1110
#[cfg(feature = "protobuf-codec")]
12-
#[allow(non_upper_case_globals)]
11+
#[allow(deprecated)]
12+
mod health;
13+
#[cfg(feature = "protobuf-codec")]
14+
mod health_grpc;
15+
#[cfg(feature = "protobuf-codec")]
1316
mod reexports {
14-
include!(concat!(env!("OUT_DIR"), "/mod.rs"));
15-
16-
pub use self::health::*;
17-
pub use self::health_grpc::*;
18-
19-
impl HealthCheckResponse_ServingStatus {
20-
pub const Unknown: HealthCheckResponse_ServingStatus =
21-
HealthCheckResponse_ServingStatus::UNKNOWN;
22-
pub const Serving: HealthCheckResponse_ServingStatus =
23-
HealthCheckResponse_ServingStatus::SERVING;
24-
pub const NotServing: HealthCheckResponse_ServingStatus =
25-
HealthCheckResponse_ServingStatus::NOT_SERVING;
26-
pub const ServiceUnknown: HealthCheckResponse_ServingStatus =
27-
HealthCheckResponse_ServingStatus::SERVICE_UNKNOWN;
28-
}
29-
30-
pub use HealthCheckResponse_ServingStatus as ServingStatus;
17+
pub use super::health::*;
18+
pub use HealthCheckResponseServingStatus as ServingStatus;
3119
}
3220

3321
pub use self::reexports::*;

health/src/proto/grpc.health.v1.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#[derive(Clone, PartialEq, ::prost::Message)]
2+
pub struct HealthCheckRequest {
3+
#[prost(string, tag="1")]
4+
pub service: ::prost::alloc::string::String,
5+
}
6+
#[derive(Clone, PartialEq, ::prost::Message)]
7+
pub struct HealthCheckResponse {
8+
#[prost(enumeration="health_check_response::ServingStatus", tag="1")]
9+
pub status: i32,
10+
}
11+
/// Nested message and enum types in `HealthCheckResponse`.
12+
pub mod health_check_response {
13+
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
14+
#[repr(i32)]
15+
pub enum ServingStatus {
16+
Unknown = 0,
17+
Serving = 1,
18+
NotServing = 2,
19+
/// Used only by the Watch method.
20+
ServiceUnknown = 3,
21+
}
22+
}
23+
const METHOD_HEALTH_CHECK: ::grpcio::Method<HealthCheckRequest, HealthCheckResponse> = ::grpcio::Method{ty: ::grpcio::MethodType::Unary, name: "/grpc.health.v1.Health/Check", req_mar: ::grpcio::Marshaller { ser: ::grpcio::pr_ser, de: ::grpcio::pr_de }, resp_mar: ::grpcio::Marshaller { ser: ::grpcio::pr_ser, de: ::grpcio::pr_de }, };
24+
const METHOD_HEALTH_WATCH: ::grpcio::Method<HealthCheckRequest, HealthCheckResponse> = ::grpcio::Method{ty: ::grpcio::MethodType::ServerStreaming, name: "/grpc.health.v1.Health/Watch", req_mar: ::grpcio::Marshaller { ser: ::grpcio::pr_ser, de: ::grpcio::pr_de }, resp_mar: ::grpcio::Marshaller { ser: ::grpcio::pr_ser, de: ::grpcio::pr_de }, };
25+
#[derive(Clone)]
26+
pub struct HealthClient { client: ::grpcio::Client }
27+
impl HealthClient {
28+
pub fn new(channel: ::grpcio::Channel) -> Self { HealthClient { client: ::grpcio::Client::new(channel) }}
29+
pub fn check_opt(&self, req: &HealthCheckRequest, opt: ::grpcio::CallOption) -> ::grpcio::Result<HealthCheckResponse,> { self.client.unary_call(&METHOD_HEALTH_CHECK, req, opt) }
30+
pub fn check(&self, req: &HealthCheckRequest) -> ::grpcio::Result<HealthCheckResponse,> { self.check_opt(req, ::grpcio::CallOption::default()) }
31+
pub fn check_async_opt(&self, req: &HealthCheckRequest, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver<HealthCheckResponse>,> { self.client.unary_call_async(&METHOD_HEALTH_CHECK, req, opt) }
32+
pub fn check_async(&self, req: &HealthCheckRequest) -> ::grpcio::Result<::grpcio::ClientUnaryReceiver<HealthCheckResponse>,> { self.check_async_opt(req, ::grpcio::CallOption::default()) }
33+
pub fn watch_opt(&self, req: &HealthCheckRequest, opt: ::grpcio::CallOption) -> ::grpcio::Result<::grpcio::ClientSStreamReceiver<HealthCheckResponse>,> { self.client.server_streaming(&METHOD_HEALTH_WATCH, req, opt) }
34+
pub fn watch(&self, req: &HealthCheckRequest) -> ::grpcio::Result<::grpcio::ClientSStreamReceiver<HealthCheckResponse>,> { self.watch_opt(req, ::grpcio::CallOption::default()) }
35+
pub fn spawn<F>(&self, f: F) where F: ::futures::Future<Output = ()> + Send + 'static {self.client.spawn(f)}
36+
}
37+
pub trait Health {
38+
fn check(&mut self, ctx: ::grpcio::RpcContext, req: HealthCheckRequest, sink: ::grpcio::UnarySink<HealthCheckResponse>);
39+
fn watch(&mut self, ctx: ::grpcio::RpcContext, req: HealthCheckRequest, sink: ::grpcio::ServerStreamingSink<HealthCheckResponse>);
40+
}
41+
pub fn create_health<S: Health + Send + Clone + 'static>(s: S) -> ::grpcio::Service {
42+
let mut builder = ::grpcio::ServiceBuilder::new();
43+
let mut instance = s.clone();
44+
builder = builder.add_unary_handler(&METHOD_HEALTH_CHECK, move |ctx, req, resp| instance.check(ctx, req, resp));
45+
let mut instance = s;
46+
builder = builder.add_server_streaming_handler(&METHOD_HEALTH_WATCH, move |ctx, req, resp| instance.watch(ctx, req, resp));
47+
builder.build()
48+
}

0 commit comments

Comments
 (0)