Skip to content

Commit

Permalink
rpc
Browse files Browse the repository at this point in the history
  • Loading branch information
sh7ning committed Aug 31, 2020
1 parent d329406 commit 2462b84
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions app/gateway/app/api/client/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,27 +47,40 @@ def execute(self, data):
msg_id = 0
data['id'] = msg_id
msg = json.dumps(data)
self.conn.sendall(msg.encode())

try:
self.conn.sendall(msg.encode())
except BrokenPipeError as e:
self.close()
raise e
except BaseException as e:
self.close()
raise Exception("rpc send message failed, error: " + str(e))

resp = self.read_line()
# print(resp)
if not resp:
self.close()
raise Exception("rpc 获取数据失败, Not resp, server gone")

resp = json.loads(resp)
try:
resp = json.loads(resp)
except BaseException as e:
# todo log
raise e

if resp.get('id') != msg_id:
raise Exception("expected id=%s, received id=%s: %s"
% (msg_id, resp.get('id'), resp.get('error')))
raise Exception("expected id=%s, received id=%s: %s" % (msg_id, resp.get('id'), resp.get('error')))

if resp.get('error') is not None:
raise Exception(resp.get('error'))

data = json.loads(resp.get('result'))
data = resp.get('result')

if data['code'] != '0':
raise Exception("rpc 获取数据失败: %s" % data['error'])

return data
return data['data']

def read_line(self):
# return self.conn.makefile().readline()
Expand Down

0 comments on commit 2462b84

Please sign in to comment.