[Kimchi-devel] [PATCH] [WoK 5/5] reload API: adding notification before reloading operation
dhbarboza82 at gmail.com
dhbarboza82 at gmail.com
Wed Jan 18 16:24:43 UTC 2017
From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
This patch adds an add_notification call to warn the UI
about the pending reload process. To allow the UI to actually
see the notification before WoK restarts, a 2 seconds wait
(value defined by the wok.NOTIFICATION_INTERVAL var in
wok.main.js) is given before sending the cherrypy.engine.restart
call.
Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
---
src/wok/i18n.py | 2 ++
src/wok/model/config.py | 15 +++++++++++++++
2 files changed, 17 insertions(+)
diff --git a/src/wok/i18n.py b/src/wok/i18n.py
index e454e31..02adcdd 100644
--- a/src/wok/i18n.py
+++ b/src/wok/i18n.py
@@ -62,4 +62,6 @@ messages = {
"WOKRES0001L": _("Request made on resource"),
"WOKROOT0001L": _("User '%(username)s' login"),
"WOKROOT0002L": _("User '%(username)s' logout"),
+
+ "WOKCONFIG0001I": _("WoK is going to restart. Existing WoK connections will be closed."),
}
diff --git a/src/wok/model/config.py b/src/wok/model/config.py
index 57c5ad8..b69f2dd 100644
--- a/src/wok/model/config.py
+++ b/src/wok/model/config.py
@@ -18,8 +18,11 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
import cherrypy
+import time
from wok.config import config, get_version
+from wok.model.notifications import add_notification
+from wok.utils import wok_log
class ConfigModel(object):
@@ -34,4 +37,16 @@ class ConfigModel(object):
'version': get_version()}
def reload(self, name):
+ add_notification('WOKCONFIG0001I', plugin_name='/')
+ # If we proceed with the cherrypy.engine.restart() right after
+ # adding the notification, the server will reboot and the
+ # opened UIs will most likely not see the notification at all. The
+ # notification interval is set in wok.main.js as:
+ #
+ # wok.NOTIFICATION_INTERVAL = 2000
+ #
+ # Inserting a time.sleep(2) here will ensure that all opened
+ # UI had the chance to see the reload notification.
+ wok_log.info('Reloading WoK in two seconds ...')
+ time.sleep(2)
cherrypy.engine.restart()
--
2.7.4
More information about the Kimchi-devel
mailing list