mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2024-08-30 18:23:09 +00:00
Delete code that will crash and change a bit of logging in websocket_handler.py
This commit is contained in:
parent
6a253971e7
commit
7e0f592330
@ -139,30 +139,6 @@ class TasksManager:
|
|||||||
@staticmethod
|
@staticmethod
|
||||||
def realtime_thread():
|
def realtime_thread():
|
||||||
console.debug('realtime zero')
|
console.debug('realtime zero')
|
||||||
while True:
|
|
||||||
if len(WebSocketHandler.connections) > 0:
|
|
||||||
print(WebSocketHandler)
|
|
||||||
WebSocketHandler.broadcast(WebSocketHandler, 'sample_data', {
|
|
||||||
'foo': 'bar',
|
|
||||||
'baz': 'Hello, World!'
|
|
||||||
})
|
|
||||||
|
|
||||||
if WebSocketHandler.host_stats.get('cpu_usage') != \
|
|
||||||
db_helper.get_latest_hosts_stats().get('cpu_usage') or \
|
|
||||||
WebSocketHandler.host_stats.get('mem_percent') != \
|
|
||||||
db_helper.get_latest_hosts_stats().get('mem_percent'):
|
|
||||||
|
|
||||||
console.debug('realtime one')
|
|
||||||
WebSocketHandler.host_stats = db_helper.get_latest_hosts_stats()
|
|
||||||
if len(WebSocketHandler.connections) > 0:
|
|
||||||
WebSocketHandler.broadcast(WebSocketHandler, 'update_host_stats', {
|
|
||||||
'cpu': WebSocketHandler.host_stats.get('cpu_usage'),
|
|
||||||
'mem': WebSocketHandler.host_stats.get('mem_percent')
|
|
||||||
})
|
|
||||||
time.sleep(4)
|
|
||||||
else:
|
|
||||||
console.debug('realtime two')
|
|
||||||
time.sleep(2)
|
|
||||||
|
|
||||||
|
|
||||||
tasks_manager = TasksManager()
|
tasks_manager = TasksManager()
|
||||||
|
@ -7,7 +7,6 @@ from app.classes.shared.models import db_helper
|
|||||||
|
|
||||||
class WebSocketHandler(tornado.websocket.WebSocketHandler):
|
class WebSocketHandler(tornado.websocket.WebSocketHandler):
|
||||||
connections = set()
|
connections = set()
|
||||||
host_stats = db_helper.get_latest_hosts_stats()
|
|
||||||
|
|
||||||
def open(self):
|
def open(self):
|
||||||
self.connections.add(self)
|
self.connections.add(self)
|
||||||
@ -16,7 +15,7 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
|
|||||||
'foo': 'bar',
|
'foo': 'bar',
|
||||||
})
|
})
|
||||||
|
|
||||||
def on_message(self, message):
|
def on_message(self, rawMessage):
|
||||||
# broadcast
|
# broadcast
|
||||||
# for client in self.connections:
|
# for client in self.connections:
|
||||||
# client.write_message(message)
|
# client.write_message(message)
|
||||||
@ -24,14 +23,16 @@ class WebSocketHandler(tornado.websocket.WebSocketHandler):
|
|||||||
# send message to client this message was sent by
|
# send message to client this message was sent by
|
||||||
# self.write_message
|
# self.write_message
|
||||||
|
|
||||||
console.debug('Got message from WebSocket connection {}'.format(message))
|
console.debug('Got message from WebSocket connection {}'.format(rawMessage))
|
||||||
|
message = json.loads(rawMessage)
|
||||||
|
console.debug('Type: {}, Data: {}'.format(message['type'], message['data']))
|
||||||
|
|
||||||
def on_close(self):
|
def on_close(self):
|
||||||
self.connections.remove(self)
|
self.connections.remove(self)
|
||||||
console.debug('Closed WebSocket connection')
|
console.debug('Closed WebSocket connection')
|
||||||
|
|
||||||
def broadcast(self, message_type: str, data):
|
def broadcast(self, message_type: str, data):
|
||||||
print(str(json.dumps({'type': message_type, 'data': data})))
|
console.debug('Sending: ' + str(json.dumps({'type': message_type, 'data': data})))
|
||||||
message = str(json.dumps({'type': message_type, 'data': data}))
|
message = str(json.dumps({'type': message_type, 'data': data}))
|
||||||
for client in self.connections:
|
for client in self.connections:
|
||||||
client.write_message(message)
|
client.write_message(message)
|
||||||
|
Loading…
Reference in New Issue
Block a user