From 2c6177bff94f5a7dc76ad0727bb38136b87882da Mon Sep 17 00:00:00 2001 From: Josh Harvey Date: Fri, 9 Dec 2016 03:07:46 +0200 Subject: [PATCH] WIP --- lib/plugins.js | 1 + lib/poller.js | 2 ++ lib/routes.js | 6 +++++- lib/settings-loader.js | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/plugins.js b/lib/plugins.js index 032fc8a3..a4f8d71a 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -94,6 +94,7 @@ function plugins (settings) { limit 1` return db.one(sql, ['config']) + .then(row => row.id) } function pollQueries (deviceTime, deviceId, deviceRec) { diff --git a/lib/poller.js b/lib/poller.js index 71b29ae1..17af68ff 100644 --- a/lib/poller.js +++ b/lib/poller.js @@ -1,6 +1,7 @@ const plugins = require('./plugins') const notifier = require('./notifier') const T = require('./time') +const logger = require('./logger') const INCOMING_TX_INTERVAL = 30 * T.seconds const LIVE_INCOMING_TX_INTERVAL = 5 * T.seconds @@ -16,6 +17,7 @@ let pi function reload (settings) { pi = plugins(settings) + logger.debug('settings reloaded in poller') } function start (settings) { diff --git a/lib/routes.js b/lib/routes.js index 2176b453..265ba0d4 100644 --- a/lib/routes.js +++ b/lib/routes.js @@ -15,6 +15,7 @@ const pairing = require('./pairing') const settingsLoader = require('./settings-loader') const plugins = require('./plugins') const helpers = require('./route-helpers') +const poller = require('./poller') module.exports = {init} @@ -396,7 +397,8 @@ function init (opts) { }) localApp.post('/dbChange', (req, res, next) => { - return settingsLoader.load() + return settingsLoader.loadLatest() + .then(poller.reload) .then(() => logger.info('Config reloaded')) .catch(err => { logger.error(err) @@ -428,6 +430,8 @@ function populateSettings (req, res, next) { } const versionId = req.headers['config-version'] + logger.debug('versionId: %s', versionId) + if (!versionId) { logger.debug('No config-version header') return res.sendStatus(400) diff --git a/lib/settings-loader.js b/lib/settings-loader.js index 5355226b..2b5ceae4 100644 --- a/lib/settings-loader.js +++ b/lib/settings-loader.js @@ -14,7 +14,7 @@ function load (versionId) { })) } -function loadLatest (versionId) { +function loadLatest () { return Promise.all([loadLatestConfig(), loadAccounts()]) .then(([config, accounts]) => ({ config,