aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/webui
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-21 13:28:53 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-21 13:28:53 +0800
commitdaca3de57364cac19d0b0eb00e71f660bad180d7 (patch)
treee349392144c88ca8a4464bd089274bdc9ee61a33 /fg21sim/webui
parentc687143defd216196d45b902604aabdeed670594 (diff)
downloadfg21sim-daca3de57364cac19d0b0eb00e71f660bad180d7.tar.bz2
webui: websocket.py: Also push current task status when connected
Diffstat (limited to 'fg21sim/webui')
-rw-r--r--fg21sim/webui/handlers/websocket.py16
-rw-r--r--fg21sim/webui/static/js/console.js2
2 files changed, 18 insertions, 0 deletions
diff --git a/fg21sim/webui/handlers/websocket.py b/fg21sim/webui/handlers/websocket.py
index e84c20c..0b854ec 100644
--- a/fg21sim/webui/handlers/websocket.py
+++ b/fg21sim/webui/handlers/websocket.py
@@ -108,6 +108,8 @@ class WSHandler(tornado.websocket.WebSocketHandler):
self.configs = self.application.configmanager
# Push current configurations to the client
self._push_configs()
+ # Also push the current task status
+ self._push_task_status()
def on_close(self):
"""Invoked when a new WebSocket is closed by the client."""
@@ -138,3 +140,17 @@ class WSHandler(tornado.websocket.WebSocketHandler):
self.write_message(message)
logger.info("WebSocket: Pushed current configurations data " +
"with validation errors to the client")
+
+ def _push_task_status(self):
+ """
+ Push to the current task status to the client.
+ """
+ msg = {"success": True,
+ "action": "push",
+ "type": "console",
+ "subtype": "status",
+ "status": self.application.task_status}
+ message = json_encode(msg)
+ logger.debug("Message of current task status: {0}".format(message))
+ self.write_message(message)
+ logger.info("WebSocket: Pushed current task status to the client")
diff --git a/fg21sim/webui/static/js/console.js b/fg21sim/webui/static/js/console.js
index 4417b6f..4b2d1b7 100644
--- a/fg21sim/webui/static/js/console.js
+++ b/fg21sim/webui/static/js/console.js
@@ -186,6 +186,8 @@ var startServerTask = function (url, task, kwargs) {
var handleWebSocketMsgConsole = function (msg) {
if (msg.subtype === "log") {
appendLogMessage(msg);
+ } else if (msg.subtype === "status") {
+ updateTaskStatus(msg.status);
} else {
console.warn("WebSocket: received message:", msg);
}