WIP
This commit is contained in:
parent
0aa457680c
commit
47db8e9ead
7 changed files with 136 additions and 114 deletions
|
|
@ -2,6 +2,9 @@
|
|||
|
||||
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()
|
||||
|
|
|
|||
22
lib/app.js
22
lib/app.js
|
|
@ -2,6 +2,8 @@ const fs = require('fs')
|
|||
const http = require('http')
|
||||
const https = require('https')
|
||||
const express = require('express')
|
||||
const loop = require('reoccur')
|
||||
|
||||
const routes = require('./routes')
|
||||
const plugins = require('./plugins')
|
||||
const logger = require('./logger')
|
||||
|
|
@ -13,6 +15,20 @@ const options = require('./options')
|
|||
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)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
function runOnce () {
|
||||
const app = express()
|
||||
const localApp = express()
|
||||
|
||||
|
|
@ -21,7 +37,8 @@ function run () {
|
|||
|
||||
return configManager.load()
|
||||
.then(config => {
|
||||
plugins.configure(config)
|
||||
return plugins.configure(config)
|
||||
.then(() => {
|
||||
plugins.startPolling()
|
||||
plugins.startCheckingNotification()
|
||||
|
||||
|
|
@ -59,9 +76,6 @@ function run () {
|
|||
console.log('lamassu-server listening on local port ' + localPort)
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
console.error(err)
|
||||
process.exit(1)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,9 @@ function loadAccounts () {
|
|||
const toFields = fieldArr => R.fromPairs(R.map(r => [r.code, r.value], fieldArr))
|
||||
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) {
|
||||
if (!data) return {}
|
||||
return R.fromPairs(R.map(toPairs, data.data.accounts))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,12 +165,12 @@ exports.loadOrConfigPlugin = loadOrConfigPlugin
|
|||
exports.configure = function configure (config) {
|
||||
cachedConfig = config
|
||||
|
||||
const accounts = configManager.loadAccounts()
|
||||
|
||||
const cryptoCodes = getCryptoCodes()
|
||||
|
||||
console.log('DEBUG30')
|
||||
|
||||
return configManager.loadAccounts()
|
||||
.then(accounts => {
|
||||
cryptoCodes.forEach(cryptoCode => {
|
||||
console.log('DEBUG31')
|
||||
const cryptoScopedConfig = configManager.cryptoScoped(cryptoCode, cachedConfig)
|
||||
|
|
@ -253,8 +253,7 @@ exports.configure = function configure (config) {
|
|||
unscopedCfg,
|
||||
accounts
|
||||
)
|
||||
|
||||
console.log('DEBUG33')
|
||||
})
|
||||
}
|
||||
|
||||
function getConfig (machineId) {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ function poll (req, res) {
|
|||
console.log('DEBUG2: %j, %s, %s', reboots, reboot, pid)
|
||||
const langs = config.languages.machineLanguages
|
||||
|
||||
console.log('DEBUG33')
|
||||
console.log('DEBUG33.1')
|
||||
|
||||
const locale = {
|
||||
currency: config.currencies.fiatCurrency,
|
||||
|
|
@ -411,8 +411,8 @@ function init (opts) {
|
|||
localApp.post('/dbChange', (req, res) => {
|
||||
return configManager.load()
|
||||
.then(config => {
|
||||
plugins.configure(config)
|
||||
logger.info('Config reloaded')
|
||||
return plugins.configure(config)
|
||||
.then(() => logger.info('Config reloaded'))
|
||||
})
|
||||
.catch(logger.error)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@
|
|||
"pify": "^2.3.0",
|
||||
"pretty-ms": "^2.1.0",
|
||||
"ramda": "^0.21.0",
|
||||
"reoccur": "^1.0.0",
|
||||
"winston": "^2.3.0"
|
||||
},
|
||||
"repository": {
|
||||
|
|
|
|||
|
|
@ -1301,6 +1301,10 @@ referrer-policy@1.0.0:
|
|||
version "1.0.0"
|
||||
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:
|
||||
version "2.0.1"
|
||||
resolved "https://registry.yarnpkg.com/repeating/-/repeating-2.0.1.tgz#5214c53a926d3552707527fbab415dbc08d06dda"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue