Skip to content
This repository has been archived by the owner on Feb 22, 2020. It is now read-only.

Commit

Permalink
Merge pull request #41 from gnes-ai/async_grpc
Browse files Browse the repository at this point in the history
fix(grpc): add stream call to index and train in grpc service
  • Loading branch information
numb3r3 authored Jul 23, 2019
2 parents 5d65678 + 1011fb7 commit f84b5c7
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 5 deletions.
4 changes: 4 additions & 0 deletions gnes/proto/gnes.proto
Original file line number Diff line number Diff line change
Expand Up @@ -207,5 +207,9 @@ service GnesRPC {
}
rpc _Call (Request) returns (Response) {
}
rpc TrainStream (stream Request) returns (Response) {
}
rpc IndexStream (stream Request) returns (Response) {
}
}

22 changes: 20 additions & 2 deletions gnes/proto/gnes_pb2.py

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

34 changes: 34 additions & 0 deletions gnes/proto/gnes_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ def __init__(self, channel):
request_serializer=gnes__pb2.Request.SerializeToString,
response_deserializer=gnes__pb2.Response.FromString,
)
self.TrainStream = channel.stream_unary(
'/gnes.GnesRPC/TrainStream',
request_serializer=gnes__pb2.Request.SerializeToString,
response_deserializer=gnes__pb2.Response.FromString,
)
self.IndexStream = channel.stream_unary(
'/gnes.GnesRPC/IndexStream',
request_serializer=gnes__pb2.Request.SerializeToString,
response_deserializer=gnes__pb2.Response.FromString,
)


class GnesRPCServicer(object):
Expand Down Expand Up @@ -69,6 +79,20 @@ def _Call(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def TrainStream(self, request_iterator, context):
# missing associated documentation comment in .proto file
pass
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def IndexStream(self, request_iterator, context):
# missing associated documentation comment in .proto file
pass
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')


def add_GnesRPCServicer_to_server(servicer, server):
rpc_method_handlers = {
Expand All @@ -92,6 +116,16 @@ def add_GnesRPCServicer_to_server(servicer, server):
request_deserializer=gnes__pb2.Request.FromString,
response_serializer=gnes__pb2.Response.SerializeToString,
),
'TrainStream': grpc.stream_unary_rpc_method_handler(
servicer.TrainStream,
request_deserializer=gnes__pb2.Request.FromString,
response_serializer=gnes__pb2.Response.SerializeToString,
),
'IndexStream': grpc.stream_unary_rpc_method_handler(
servicer.IndexStream,
request_deserializer=gnes__pb2.Request.FromString,
response_serializer=gnes__pb2.Response.SerializeToString,
),
}
generic_handler = grpc.method_handlers_generic_handler(
'gnes.GnesRPC', rpc_method_handlers)
Expand Down
10 changes: 10 additions & 0 deletions gnes/service/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ def Index(self, request, context):
def Search(self, request, context):
return self._Call(request, context)

def TrainStream(self, request_iterator, context):
for request in request_iterator:
ret = self._Call(request, context)
return ret

def IndexStream(self, request_iterator, context):
for request in request_iterator:
ret = self._Call(request, context)
return ret


class GRPCFrontend:
def __init__(self, args):
Expand Down
6 changes: 3 additions & 3 deletions shell/make-proto.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env bash

SRC_DIR=../gnes/proto/
PLUGIN_PATH=/Volumes/TOSHIBA-4T/Documents/grpc/bins/opt/grpc_python_plugin
#PLUGIN_PATH=/Users/yanlarry/Desktop/git/grpc/bins/opt/grpc_python_plugin
#PLUGIN_PATH=/Volumes/TOSHIBA-4T/Documents/grpc/bins/opt/grpc_python_plugin
PLUGIN_PATH=/user/local/grpc/bins/opt/grpc_python_plugin

protoc -I ${SRC_DIR} --python_out=${SRC_DIR} --grpc_python_out=${SRC_DIR} --plugin=protoc-gen-grpc_python=${PLUGIN_PATH} ${SRC_DIR}gnes.proto

# fix import bug in google generator
sed -i '' -e '4s/.*/from\ \.\ import\ gnes_pb2\ as\ gnes__pb2/' ${SRC_DIR}gnes_pb2_grpc.py
sed -i '' -e '4s/.*/from\ \.\ import\ gnes_pb2\ as\ gnes__pb2/' ${SRC_DIR}gnes_pb2_grpc.py

0 comments on commit f84b5c7

Please sign in to comment.