为websocket增加ping响应

main
RogerWork 10 months ago
parent 15ed79245c
commit 613c56700a
  1. 8
      update/consumers.py
  2. 9
      update/views.py

@ -12,8 +12,12 @@ class UpdateConsumer(WebsocketConsumer):
if text_data is None: if text_data is None:
self.send('你发了啥') self.send('你发了啥')
else: else:
if text_data.startswith('ip:'): data = json.loads(text_data)
ip = text_data.replace('ip:', '') 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))) self.send(json.dumps(cinema_update_status.get(ip, None)))
else: else:
self.send(text_data) self.send(text_data)

@ -140,6 +140,7 @@ def update_cine(request):
print('git', e) print('git', e)
cinema_update_status[cinema_ip]['git']['result'] = 'fail' cinema_update_status[cinema_ip]['git']['result'] = 'fail'
cinema_update_status[cinema_ip]['git']['msg'] = str(e) cinema_update_status[cinema_ip]['git']['msg'] = str(e)
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)})
# 执行setup # 执行setup
print('执行setup') print('执行setup')
@ -154,6 +155,7 @@ def update_cine(request):
print('setup', e) print('setup', e)
cinema_update_status[cinema_ip]['setup']['result'] = 'fail' cinema_update_status[cinema_ip]['setup']['result'] = 'fail'
cinema_update_status[cinema_ip]['setup']['msg'] = str(e) 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'])) sql_list = list(set(cmd_list) & set(cmd_dict['sql']))
@ -169,6 +171,7 @@ def update_cine(request):
print('sql', e) print('sql', e)
cinema_update_status[cinema_ip]['sql']['result'] = 'fail' cinema_update_status[cinema_ip]['sql']['result'] = 'fail'
cinema_update_status[cinema_ip]['sql']['msg'] = str(e) cinema_update_status[cinema_ip]['sql']['msg'] = str(e)
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)})
# 修改设置 # 修改设置
print('执行config(teardown前)') print('执行config(teardown前)')
@ -183,6 +186,7 @@ def update_cine(request):
print('config', e) print('config', e)
cinema_update_status[cinema_ip]['config']['result'] = 'fail' cinema_update_status[cinema_ip]['config']['result'] = 'fail'
cinema_update_status[cinema_ip]['config']['msg'] = str(e) cinema_update_status[cinema_ip]['config']['msg'] = str(e)
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)})
# 执行teardown # 执行teardown
teardown_list = list(set(cmd_list) & set(cmd_dict['teardown'])) teardown_list = list(set(cmd_list) & set(cmd_dict['teardown']))
@ -198,6 +202,7 @@ def update_cine(request):
print('teardown', e) print('teardown', e)
cinema_update_status[cinema_ip]['teardown']['result'] = 'fail' cinema_update_status[cinema_ip]['teardown']['result'] = 'fail'
cinema_update_status[cinema_ip]['teardown']['msg'] = str(e) cinema_update_status[cinema_ip]['teardown']['msg'] = str(e)
return JsonResponse({'result': 'fail', 'ip': cinema_ip, 'msg': str(e)})
# 修改设置 # 修改设置
print('执行config(teardown后)') print('执行config(teardown后)')
@ -212,6 +217,7 @@ def update_cine(request):
print('config', e) print('config', e)
cinema_update_status[cinema_ip]['config']['result'] = 'fail' cinema_update_status[cinema_ip]['config']['result'] = 'fail'
cinema_update_status[cinema_ip]['config']['msg'] = update_status['config']['msg'] + '\n' + str(e) 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'])) client_list = list(set(cmd_list) & set(cmd_dict['client']))
@ -226,9 +232,10 @@ def update_cine(request):
print('client', e) print('client', e)
cinema_update_status[cinema_ip]['client']['result'] = 'fail' cinema_update_status[cinema_ip]['client']['result'] = 'fail'
cinema_update_status[cinema_ip]['client']['msg'] = str(e) 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]) print(cinema_update_status[cinema_ip])
return JsonResponse({'result': 'success', 'ip': cinema_ip}) return JsonResponse({'result': 'success', 'ip': cinema_ip, 'msg': ''})
# # 测试用接口 # # 测试用接口

Loading…
Cancel
Save