From 8c2d30547cfcdfc82f7051f6b9435df3e46ca177 Mon Sep 17 00:00:00 2001 From: virusdefender Date: Fri, 22 Dec 2017 22:16:03 +0800 Subject: [PATCH] log heartbeat response --- server/service.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/server/service.py b/server/service.py index c6d25cd..b513906 100644 --- a/server/service.py +++ b/server/service.py @@ -16,13 +16,20 @@ class JudgeService(object): def _request(self, data): try: - r = requests.post(self.backend_url, json=data, - headers={"X-JUDGE-SERVER-TOKEN": token}, timeout=5).json() + resp = requests.post(self.backend_url, json=data, + headers={"X-JUDGE-SERVER-TOKEN": token, + "Content-Type": "application/json"}, timeout=5).text except Exception as e: logger.exception(e) - raise JudgeServiceError(e.message) - if r["error"]: - raise JudgeServiceError(r["data"]) + raise JudgeServiceError("Heartbeat request failed") + try: + r = json.loads(resp) + if r["error"]: + raise JudgeServiceError(r["data"]) + except Exception as e: + logger.exception("Heartbeat failed, response is {}".format(resp)) + raise JudgeServiceError("Invalid heartbeat response") + def heartbeat(self): data = server_info()