Add runtime state tracking to Nightscout, where client now checks if the server has loaded initial data from Mongo before the user is directed to the UI

This commit is contained in:
Sulka Haro
2020-11-14 11:05:43 +02:00
parent ead1370490
commit 376c790710
7 changed files with 21 additions and 3 deletions
+1
View File
@@ -32,6 +32,7 @@ function configure (app, wares, env, ctx) {
, settings: settings
, extendedSettings: extended
, authorized: ctx.authorization.authorize(authToken)
, runtimeState: ctx.runtimeState
};
var badge = 'http://img.shields.io/badge/Nightscout-OK-green';
+6
View File
@@ -62,6 +62,12 @@ client.init = function init (callback) {
, url: src
, headers: client.headers()
}).done(function success (serverSettings) {
if (serverSettings.runtimeState !== 'loaded') {
console.log('Server is still loading data');
$('#loadingMessageText').html('Server is loading data, retrying load in 2 seconds');
window.setTimeout(window.Nightscout.client.init(), 2000);
return;
}
client.settingsFailed = false;
console.log('Application appears to be online');
$('#centerMessagePanel').hide();
-2
View File
@@ -67,8 +67,6 @@ function init (ctx) {
var prop = sbx.properties.ar2;
console.log('ar2', prop);
if (prop && prop.level) {
const notify = {
level: prop.level
+1
View File
@@ -75,6 +75,7 @@ function init (ctx) {
, require('./timeago')(ctx)
, require('./basalprofile')(ctx)
, require('./dbsize')(ctx)
, require('./runtimestate')(ctx)
];
plugins.registerServerDefaults = function registerServerDefaults () {
+1
View File
@@ -45,6 +45,7 @@ function init () {
reset();
sbx.runtimeEnvironment = 'server';
sbx.runtimeState = ctx.runtimeState;
sbx.time = Date.now();
sbx.settings = env.settings;
sbx.data = ctx.ddata.clone();
+11
View File
@@ -6,6 +6,11 @@ var UPDATE_THROTTLE = 5000;
function boot (env, language) {
function startBoot(ctx, next) {
ctx.runtimeState = 'booting';
next();
}
//////////////////////////////////////////////////
// Check Node version.
// Latest Node 8 LTS and Latest Node 10 LTS are recommended and supported.
@@ -255,6 +260,10 @@ function boot (env, language) {
ctx.bus.emit('data-processed');
});
ctx.bus.on('data-processed', function processed ( ) {
ctx.runtimeState = 'loaded';
});
ctx.bus.on('notification', ctx.pushnotify.emitNotification);
next( );
@@ -289,12 +298,14 @@ function boot (env, language) {
return next();
}
ctx.runtimeState = 'booted';
ctx.bus.uptime( );
next( );
}
return require('bootevent')( )
.acquire(startBoot)
.acquire(checkNodeVersion)
.acquire(checkEnv)
.acquire(augmentSettings)
+1 -1
View File
@@ -167,7 +167,7 @@ function init () {
}
//TODO: getting sent in status.json, shouldn't be
settings.DEFAULT_FEATURES = ['bgnow', 'delta', 'direction', 'timeago', 'devicestatus', 'upbat', 'errorcodes', 'profile', 'dbsize'];
settings.DEFAULT_FEATURES = ['bgnow', 'delta', 'direction', 'timeago', 'devicestatus', 'upbat', 'errorcodes', 'profile', 'dbsize', 'runtimestate'];
var wasSet = [];