Skip to content

Commit

Permalink
define example logging hooks in R
Browse files Browse the repository at this point in the history
  • Loading branch information
daroczig committed Aug 22, 2018
1 parent 5ae9a7f commit 4409da0
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 9 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Expand Up @@ -10,7 +10,8 @@ Encoding: UTF-8
LazyData: true
Imports:
Rcpp (>= 0.12.5),
RProtoBuf
RProtoBuf,
futile.logger
Suggests:
testthat,
processx
Expand Down
4 changes: 4 additions & 0 deletions NAMESPACE
Expand Up @@ -2,6 +2,7 @@

export(grpc_client)
export(grpc_debug)
export(grpc_default_hooks)
export(grpc_version)
export(newResponse)
export(read_services)
Expand All @@ -11,6 +12,9 @@ importFrom(RProtoBuf,new)
importFrom(RProtoBuf,read)
importFrom(RProtoBuf,readProtoFiles)
importFrom(RProtoBuf,serialize)
importFrom(futile.logger,flog.debug)
importFrom(futile.logger,flog.info)
importFrom(futile.logger,flog.trace)
importFrom(methods,selectMethod)
importFrom(utils,assignInMyNamespace)
useDynLib(grpc)
5 changes: 2 additions & 3 deletions R/server.R
Expand Up @@ -8,9 +8,8 @@
#' @importFrom RProtoBuf P serialize read
#' @useDynLib grpc
#' @export
start_server <- function(impl, channel, hooks = list(
bind = function(params) cat('gRPC service will listen on port', params$port, '\n'),
run = function(params) cat('gRPC service started on port', params$port, '\n'))) {
#' @seealso \code{\link{grpc_default_hooks}}
start_server <- function(impl, channel, hooks = grpc_default_hooks()) {

server_functions <- lapply(impl, function(fn){
descriptor <- P(fn[["RequestType"]]$proto)
Expand Down
6 changes: 5 additions & 1 deletion README.md
Expand Up @@ -25,7 +25,11 @@ There are runnable examples in the `demo/` folder.
To start a HelloWorld server:

R -e 'demo("helloserver", "grpc")'


Or with much more detailed logging:

R -e 'library(futile.logger); flog.threshold(TRACE); demo("helloserver", "grpc")'

To run a client against a running HelloWorld server:

R -e 'demo("helloclient", "grpc")'
Expand Down
14 changes: 14 additions & 0 deletions man/grpc_default_hooks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions man/start_server.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/server.cpp
Expand Up @@ -296,7 +296,7 @@ List run(List target, CharacterVector hoststring, List hooks) {

//shutdown
RGRPC_LOG("Shutting down\n");
runFunctionIfProvided(hooks, "preshutdown", params);
runFunctionIfProvided(hooks, "shutdown", params);
grpc_server_shutdown_and_notify(server, queue, 0 /* tag */);
grpc_server_cancel_all_calls(server);
grpc_completion_queue_next(queue, gpr_inf_future(GPR_CLOCK_REALTIME), NULL);
Expand Down

0 comments on commit 4409da0

Please sign in to comment.