diff --git a/update/consumers.py b/update/consumers.py index 590be04..b007843 100644 --- a/update/consumers.py +++ b/update/consumers.py @@ -12,8 +12,12 @@ class UpdateConsumer(WebsocketConsumer): if text_data is None: self.send('你发了啥') else: - if text_data.startswith('ip:'): - ip = text_data.replace('ip:', '') + data = json.loads(text_data) + if data.get('msg', False): + if data['msg'] == 'ping': + self.send(json.dumps({'msg': 'pong'})) + if data.get('ip', False): + ip = data['ip'] self.send(json.dumps(cinema_update_status.get(ip, None))) else: self.send(text_data) diff --git a/update/views.py b/update/views.py index 3d782a1..01fa0e7 100644 --- a/update/views.py +++ b/update/views.py @@ -140,6 +140,7 @@ def update_cine(request): print('git', e) cinema_update_status[cinema_ip]['git']['result'] = 'fail' cinema_update_status[cinema_ip]['git']['msg'] = str(e) + return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)}) # 执行setup print('执行setup') @@ -154,6 +155,7 @@ def update_cine(request): print('setup', e) cinema_update_status[cinema_ip]['setup']['result'] = 'fail' cinema_update_status[cinema_ip]['setup']['msg'] = str(e) + return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)}) # 数据库对比 sql_list = list(set(cmd_list) & set(cmd_dict['sql'])) @@ -169,6 +171,7 @@ def update_cine(request): print('sql', e) cinema_update_status[cinema_ip]['sql']['result'] = 'fail' cinema_update_status[cinema_ip]['sql']['msg'] = str(e) + return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)}) # 修改设置 print('执行config(teardown前)') @@ -183,6 +186,7 @@ def update_cine(request): print('config', e) cinema_update_status[cinema_ip]['config']['result'] = 'fail' cinema_update_status[cinema_ip]['config']['msg'] = str(e) + return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)}) # 执行teardown teardown_list = list(set(cmd_list) & set(cmd_dict['teardown'])) @@ -198,6 +202,7 @@ def update_cine(request): print('teardown', e) cinema_update_status[cinema_ip]['teardown']['result'] = 'fail' cinema_update_status[cinema_ip]['teardown']['msg'] = str(e) + return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)}) # 修改设置 print('执行config(teardown后)') @@ -212,6 +217,7 @@ def update_cine(request): print('config', e) cinema_update_status[cinema_ip]['config']['result'] = 'fail' cinema_update_status[cinema_ip]['config']['msg'] = update_status['config']['msg'] + '\n' + str(e) + return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)}) # 传输客户端 client_list = list(set(cmd_list) & set(cmd_dict['client'])) @@ -226,9 +232,10 @@ def update_cine(request): print('client', e) cinema_update_status[cinema_ip]['client']['result'] = 'fail' cinema_update_status[cinema_ip]['client']['msg'] = str(e) + return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)}) print(cinema_update_status[cinema_ip]) - return JsonResponse({'result': 'success', 'ip': cinema_ip}) + return JsonResponse({'result': 'success', 'ip': cinema_ip, 'msg': ''}) # # 测试用接口