This commit is contained in:
Josh Harvey 2016-11-19 02:13:06 +02:00
parent 0aa457680c
commit 47db8e9ead
7 changed files with 136 additions and 114 deletions

View file

@ -2,6 +2,9 @@
const app = require('../lib/app') const app = require('../lib/app')
process.on('unhandledRejection', err => console.log(err.stack)) process.on('unhandledRejection', err => {
console.log('Unhandled rejection')
console.log(err.stack)
})
app.run() app.run()

View file

@ -2,6 +2,8 @@ const fs = require('fs')
const http = require('http') const http = require('http')
const https = require('https') const https = require('https')
const express = require('express') const express = require('express')
const loop = require('reoccur')
const routes = require('./routes') const routes = require('./routes')
const plugins = require('./plugins') const plugins = require('./plugins')
const logger = require('./logger') const logger = require('./logger')
@ -13,6 +15,20 @@ const options = require('./options')
const devMode = argv.dev || argv.http || options.http const devMode = argv.dev || argv.http || options.http
function run () { 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)
})
})
}
function runOnce () {
const app = express() const app = express()
const localApp = express() const localApp = express()
@ -21,7 +37,8 @@ function run () {
return configManager.load() return configManager.load()
.then(config => { .then(config => {
plugins.configure(config) return plugins.configure(config)
.then(() => {
plugins.startPolling() plugins.startPolling()
plugins.startCheckingNotification() plugins.startCheckingNotification()
@ -59,9 +76,6 @@ function run () {
console.log('lamassu-server listening on local port ' + localPort) console.log('lamassu-server listening on local port ' + localPort)
}) })
}) })
.catch(err => {
console.error(err)
process.exit(1)
}) })
} }

View file

@ -12,8 +12,9 @@ function loadAccounts () {
const toFields = fieldArr => R.fromPairs(R.map(r => [r.code, r.value], fieldArr)) const toFields = fieldArr => R.fromPairs(R.map(r => [r.code, r.value], fieldArr))
const toPairs = r => [r.code, toFields(r.fields)] const toPairs = r => [r.code, toFields(r.fields)]
return db.one('select data from user_config where type=$1', 'accounts') return db.oneOrNone('select data from user_config where type=$1', 'accounts')
.then(function (data) { .then(function (data) {
if (!data) return {}
return R.fromPairs(R.map(toPairs, data.data.accounts)) return R.fromPairs(R.map(toPairs, data.data.accounts))
}) })
} }

View file

@ -165,12 +165,12 @@ exports.loadOrConfigPlugin = loadOrConfigPlugin
exports.configure = function configure (config) { exports.configure = function configure (config) {
cachedConfig = config cachedConfig = config
const accounts = configManager.loadAccounts()
const cryptoCodes = getCryptoCodes() const cryptoCodes = getCryptoCodes()
console.log('DEBUG30') console.log('DEBUG30')
return configManager.loadAccounts()
.then(accounts => {
cryptoCodes.forEach(cryptoCode => { cryptoCodes.forEach(cryptoCode => {
console.log('DEBUG31') console.log('DEBUG31')
const cryptoScopedConfig = configManager.cryptoScoped(cryptoCode, cachedConfig) const cryptoScopedConfig = configManager.cryptoScoped(cryptoCode, cachedConfig)
@ -253,8 +253,7 @@ exports.configure = function configure (config) {
unscopedCfg, unscopedCfg,
accounts accounts
) )
})
console.log('DEBUG33')
} }
function getConfig (machineId) { function getConfig (machineId) {

View file

@ -87,7 +87,7 @@ function poll (req, res) {
console.log('DEBUG2: %j, %s, %s', reboots, reboot, pid) console.log('DEBUG2: %j, %s, %s', reboots, reboot, pid)
const langs = config.languages.machineLanguages const langs = config.languages.machineLanguages
console.log('DEBUG33') console.log('DEBUG33.1')
const locale = { const locale = {
currency: config.currencies.fiatCurrency, currency: config.currencies.fiatCurrency,
@ -411,8 +411,8 @@ function init (opts) {
localApp.post('/dbChange', (req, res) => { localApp.post('/dbChange', (req, res) => {
return configManager.load() return configManager.load()
.then(config => { .then(config => {
plugins.configure(config) return plugins.configure(config)
logger.info('Config reloaded') .then(() => logger.info('Config reloaded'))
}) })
.catch(logger.error) .catch(logger.error)
}) })

View file

@ -35,6 +35,7 @@
"pify": "^2.3.0", "pify": "^2.3.0",
"pretty-ms": "^2.1.0", "pretty-ms": "^2.1.0",
"ramda": "^0.21.0", "ramda": "^0.21.0",
"reoccur": "^1.0.0",
"winston": "^2.3.0" "winston": "^2.3.0"
}, },
"repository": { "repository": {

View file

@ -1301,6 +1301,10 @@ referrer-policy@1.0.0:
version "1.0.0" version "1.0.0"
resolved "https://registry.yarnpkg.com/referrer-policy/-/referrer-policy-1.0.0.tgz#f60eedc92f942b01a6118121ec932d66e8fd7e14" resolved "https://registry.yarnpkg.com/referrer-policy/-/referrer-policy-1.0.0.tgz#f60eedc92f942b01a6118121ec932d66e8fd7e14"
reoccur:
version "1.0.0"
resolved "https://registry.yarnpkg.com/reoccur/-/reoccur-1.0.0.tgz#62578914654cfe7583caf7a609ed30a3e9a4197d"
repeating@^2.0.0: repeating@^2.0.0:
version "2.0.1" version "2.0.1"
resolved "https://registry.yarnpkg.com/repeating/-/repeating-2.0.1.tgz#5214c53a926d3552707527fbab415dbc08d06dda" resolved "https://registry.yarnpkg.com/repeating/-/repeating-2.0.1.tgz#5214c53a926d3552707527fbab415dbc08d06dda"