From 4baff1a96fdacd0da55c59c75b5ad14bf7410600 Mon Sep 17 00:00:00 2001 From: echel0n Date: Wed, 25 Jun 2014 18:40:36 -0700 Subject: [PATCH] Improved restart template and js code to act like it used to but still function properly with Tornado. --- gui/slick/js/restart.js | 70 +++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/gui/slick/js/restart.js b/gui/slick/js/restart.js index 9ff51ab0..293ca3b3 100644 --- a/gui/slick/js/restart.js +++ b/gui/slick/js/restart.js @@ -16,39 +16,7 @@ var timeout_id; var restarted = ''; var num_restart_waits = 0; -function is_alive() { - timeout_id = 0; - $.get(is_alive_url, function(data) { - - // if it's still initalizing then just wait and try again - if (data.msg == 'nope') { - $('#shut_down_loading').hide(); - $('#shut_down_success').show(); - $('#restart_message').show(); - setTimeout('is_alive()', 1000); - } else { - // if this is before we've even shut down then just try again later - if (restarted == '' || data.restarted == restarted) { - restarted = data.restarted; - setTimeout('is_alive()', 1000); - - // if we're ready to go then redirect to new url - } else { - $('#restart_loading').hide(); - $('#restart_success').show(); - $('#refresh_message').show(); - window.location = sb_base_url+'/home/'; - } - } - }, 'jsonp'); -} - -$(document).ready(function() -{ - - is_alive(); - - $(document).ajaxError(function(e, jqxhr, settings, exception) { +function restartHandler() { num_restart_waits += 1; $('#shut_down_loading').hide(); @@ -68,6 +36,14 @@ $(document).ready(function() }, 3000); setTimeout("window.location = sb_base_url+'/home/'", 5000); } + } else { + timeout_id = 1; + setTimeout(function(){ + $('#restart_loading').hide(); + $('#restart_success').show(); + $('#refresh_message').show(); + }, 3000); + setTimeout("window.location = sb_base_url+'/home/'", 5000); } // if it is taking forever just give up @@ -80,6 +56,32 @@ $(document).ready(function() if (timeout_id == 0) timeout_id = setTimeout('is_alive()', 1000); - }); +} +function is_alive() { + timeout_id = 0; + + $.get(is_alive_url, function(data) { + + // if it's still initalizing then just wait and try again + if (data.msg == 'nope') { + $('#shut_down_loading').hide(); + $('#shut_down_success').show(); + $('#restart_message').show(); + setTimeout('is_alive()', 1000); + } else if (data.restarted == 'True') { + restartHandler(); + } else { + // if this is before we've even shut down then just try again later + if (restarted == '' || data.restarted == restarted) { + restarted = data.restarted; + setTimeout(is_alive, 1000); + } + } + }, 'jsonp'); +} + +$(document).ready(function() +{ + is_alive(); });