From db79f958c8c372e3b0107864fb6f8d4d2cc7c24d Mon Sep 17 00:00:00 2001 From: Josh Harvey Date: Sat, 10 Dec 2016 00:11:34 +0200 Subject: [PATCH] don't start l-s until config is valid --- lib/app.js | 29 ++++++++++++++++------------- lib/verify-schema.js | 12 ++++++++++++ package.json | 1 - public/styles.css | 3 ++- yarn.lock | 10 +--------- 5 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 lib/verify-schema.js diff --git a/lib/app.js b/lib/app.js index 700be241..3810e9fa 100644 --- a/lib/app.js +++ b/lib/app.js @@ -2,13 +2,12 @@ const fs = require('fs') const http = require('http') const https = require('https') const express = require('express') -const loop = require('reoccur') const argv = require('minimist')(process.argv.slice(2)) const routes = require('./routes') const logger = require('./logger') const poller = require('./poller') - +const verifySchema = require('./verify-schema') const settingsLoader = require('./settings-loader') const options = require('./options') @@ -16,23 +15,27 @@ const devMode = argv.dev || argv.http || options.http function run () { let count = 0 - return loop((recur, resolve, reject) => { - return runOnce() - .then(resolve) - .catch(err => { - count += 1 - logger.debug(err) - logger.debug('[%d] Retrying in 10s...', count) - setTimeout(recur, 10000) - }) - }) + + const errorHandler = err => { + count += 1 + logger.error(err) + logger.error('[%d] Retrying in 10s...', count) + } + + const runner = () => runOnce() + .then(() => clearInterval(handler)) + .catch(errorHandler) + + const handler = setInterval(runner, 10000) + return runner() } function runOnce () { const app = express() const localApp = express() - return settingsLoader.loadLatest() + return verifySchema.valid() + .then(() => settingsLoader.loadLatest()) .then(settings => { poller.start(settings) diff --git a/lib/verify-schema.js b/lib/verify-schema.js new file mode 100644 index 00000000..94e084d0 --- /dev/null +++ b/lib/verify-schema.js @@ -0,0 +1,12 @@ +const util = require('util') +const config = require('./admin/config') + +function valid () { + return config.validateConfig() + .then(errors => { + if (errors.length === 0) return + throw new Error('Schema validation error: ' + util.inspect(errors, {colors: true})) + }) +} + +module.exports = {valid} diff --git a/package.json b/package.json index ae75aad5..03128e40 100644 --- a/package.json +++ b/package.json @@ -36,7 +36,6 @@ "pify": "^2.3.0", "pretty-ms": "^2.1.0", "ramda": "^0.22.1", - "reoccur": "^1.0.0", "serve-static": "^1.11.1", "uuid": "^3.0.0", "winston": "^2.3.0" diff --git a/public/styles.css b/public/styles.css index 1f0e63f1..c6ed0bed 100644 --- a/public/styles.css +++ b/public/styles.css @@ -346,7 +346,8 @@ p { .lamassuAdminNavBar { margin: 0; - padding: 0; + padding: 0 0 60px 0; + background-color: #2d2d2d; font-size: 18px; } diff --git a/yarn.lock b/yarn.lock index df61c529..803e1c3e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1969,10 +1969,6 @@ regenerator@~0.8.13: regenerator-runtime "~0.9.5" through "~2.3.8" -reoccur@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/reoccur/-/reoccur-1.0.0.tgz#62578914654cfe7583caf7a609ed30a3e9a4197d" - repeat-string@^1.5.2: version "1.6.1" resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637" @@ -2353,11 +2349,7 @@ underscore.string@2.4.0, underscore.string@~2.4.0: version "2.4.0" resolved "https://registry.yarnpkg.com/underscore.string/-/underscore.string-2.4.0.tgz#8cdd8fbac4e2d2ea1e7e2e8097c42f442280f85b" -underscore@1.x: - version "1.8.3" - resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.8.3.tgz#4f3fb53b106e6097fcf9cb4109f2a5e9bdfa5022" - -underscore@~1.7.0: +underscore@1.x, underscore@~1.7.0: version "1.7.0" resolved "https://registry.yarnpkg.com/underscore/-/underscore-1.7.0.tgz#6bbaf0877500d36be34ecaa584e0db9fef035209"