fix sanctions db updating in app.js

This commit is contained in:
Josh Harvey 2018-05-07 14:57:49 +03:00
parent 5ba164e566
commit 5cc2d63d0a
4 changed files with 22 additions and 19 deletions

View file

@ -9,6 +9,7 @@ const poller = require('./poller')
const settingsLoader = require('./settings-loader') const settingsLoader = require('./settings-loader')
const options = require('./options') const options = require('./options')
const ofac = require('./ofac/index') const ofac = require('./ofac/index')
const ofacUpdate = require('./ofac/update')
const devMode = argv.dev || options.http const devMode = argv.dev || options.http
@ -17,6 +18,7 @@ logger.info('Version: %s', version)
function run () { function run () {
let count = 0 let count = 0
let handler
const errorHandler = err => { const errorHandler = err => {
count += 1 count += 1
@ -28,14 +30,21 @@ function run () {
.then(() => clearInterval(handler)) .then(() => clearInterval(handler))
.catch(errorHandler) .catch(errorHandler)
const handler = setInterval(runner, 10000) return loadSanctions()
return runner() .then(() => { handler = setInterval(runner, 10000) })
.then(runner)
}
function loadSanctions () {
logger.info('Loading sanctions DB...')
return ofacUpdate.update()
.then(() => logger.info('Sanctions DB updated'))
.then(ofac.load)
.then(() => logger.info('Sanctions DB loaded'))
} }
function runOnce () { function runOnce () {
logger.info('Loading sanctions DB...') return settingsLoader.loadLatest()
return ofac.load()
.then(settingsLoader.loadLatest)
.then(settings => { .then(settings => {
poller.start(settings) poller.start(settings)

View file

@ -49,7 +49,6 @@ function start (__settings) {
cashOutTx.monitorUnnotified(settings()) cashOutTx.monitorUnnotified(settings())
pi().sweepHd() pi().sweepHd()
notifier.checkNotification(pi()) notifier.checkNotification(pi())
updateAndLoadSanctions()
setInterval(() => pi().executeTrades(), TRADE_INTERVAL) setInterval(() => pi().executeTrades(), TRADE_INTERVAL)
setInterval(() => cashOutTx.monitorLiveIncoming(settings()), LIVE_INCOMING_TX_INTERVAL) setInterval(() => cashOutTx.monitorLiveIncoming(settings()), LIVE_INCOMING_TX_INTERVAL)

19
package-lock.json generated
View file

@ -1154,7 +1154,7 @@
"bitcore-lib": { "bitcore-lib": {
"version": "0.15.0", "version": "0.15.0",
"resolved": "https://registry.npmjs.org/bitcore-lib/-/bitcore-lib-0.15.0.tgz", "resolved": "https://registry.npmjs.org/bitcore-lib/-/bitcore-lib-0.15.0.tgz",
"integrity": "sha1-+SS+E4afKqt+BK7sVkKtM1m2zsI=", "integrity": "sha512-AeXLWhiivF6CDFzrABZHT4jJrflyylDWTi32o30rF92HW9msfuKpjzrHtFKYGa9w0kNVv5HABQjCB3OEav4PhQ==",
"requires": { "requires": {
"bn.js": "4.11.8", "bn.js": "4.11.8",
"bs58": "4.0.1", "bs58": "4.0.1",
@ -6404,7 +6404,7 @@
"pg": { "pg": {
"version": "7.4.1", "version": "7.4.1",
"resolved": "https://registry.npmjs.org/pg/-/pg-7.4.1.tgz", "resolved": "https://registry.npmjs.org/pg/-/pg-7.4.1.tgz",
"integrity": "sha1-80Ecjd+faSMi/gXnAXoYiOR/ePE=", "integrity": "sha512-Pi5qYuXro5PAD9xXx8h7bFtmHgAQEG6/SCNyi7gS3rvb/ZQYDmxKchfB0zYtiSJNWq9iXTsYsHjrM+21eBcN1A==",
"requires": { "requires": {
"buffer-writer": "1.0.1", "buffer-writer": "1.0.1",
"js-string-escape": "1.0.1", "js-string-escape": "1.0.1",
@ -6447,7 +6447,7 @@
"pg-int8": { "pg-int8": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz", "resolved": "https://registry.npmjs.org/pg-int8/-/pg-int8-1.0.1.tgz",
"integrity": "sha1-lDvUY79bcbQXARX4D478mgwOt4w=" "integrity": "sha512-WCtabS6t3c8SkpDBUlb1kjOs7l66xsGdKpIPZsg4wR+B3+u9UAum2odSsF9tnvxg80h4ZxLWMy4pRjOsFIqQpw=="
}, },
"pg-native": { "pg-native": {
"version": "2.2.0", "version": "2.2.0",
@ -6497,7 +6497,7 @@
"pg-promise": { "pg-promise": {
"version": "7.4.1", "version": "7.4.1",
"resolved": "https://registry.npmjs.org/pg-promise/-/pg-promise-7.4.1.tgz", "resolved": "https://registry.npmjs.org/pg-promise/-/pg-promise-7.4.1.tgz",
"integrity": "sha1-uyDjnS0ObUXZLwu6szidHmEXlxo=", "integrity": "sha512-WlELd86G2ucrFbomdn+UfOeLMeFuPd/v8qXvn0rXgcxWfuxkn1fU3nKmaEnNFuDaOykDnO4bkxL6O0vnJi+HHg==",
"requires": { "requires": {
"manakin": "0.5.1", "manakin": "0.5.1",
"pg": "7.4.1", "pg": "7.4.1",
@ -6866,11 +6866,6 @@
"resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz", "resolved": "https://registry.npmjs.org/qs/-/qs-6.4.0.tgz",
"integrity": "sha1-E+JtKK1rD/qpExLNO/cI7TUecjM=" "integrity": "sha1-E+JtKK1rD/qpExLNO/cI7TUecjM="
}, },
"ramda": {
"version": "0.22.1",
"resolved": "https://registry.npmjs.org/ramda/-/ramda-0.22.1.tgz",
"integrity": "sha1-Ax2gw99BfFszyWI0dX6zcDPzag4="
},
"randomatic": { "randomatic": {
"version": "1.1.7", "version": "1.1.7",
"resolved": "https://registry.npmjs.org/randomatic/-/randomatic-1.1.7.tgz", "resolved": "https://registry.npmjs.org/randomatic/-/randomatic-1.1.7.tgz",
@ -8423,9 +8418,9 @@
"integrity": "sha1-+OGqHuWlPsW/FR/6CXQqatdpeHY=" "integrity": "sha1-+OGqHuWlPsW/FR/6CXQqatdpeHY="
}, },
"winston": { "winston": {
"version": "2.3.1", "version": "2.4.2",
"resolved": "https://registry.npmjs.org/winston/-/winston-2.3.1.tgz", "resolved": "https://registry.npmjs.org/winston/-/winston-2.4.2.tgz",
"integrity": "sha1-C0hCDZeMAYBM8CMLZIhhWYIloRk=", "integrity": "sha512-4S/Ad4ZfSNl8OccCLxnJmNISWcm2joa6Q0YGDxlxMzH0fgSwWsjMt+SmlNwCqdpaPg3ev1HKkMBsIiXeSUwpbA==",
"requires": { "requires": {
"async": "1.0.0", "async": "1.0.0",
"colors": "1.0.3", "colors": "1.0.3",

View file

@ -55,7 +55,7 @@
"twilio": "^3.6.1", "twilio": "^3.6.1",
"uuid": "^3.1.0", "uuid": "^3.1.0",
"web3": "^0.19.1", "web3": "^0.19.1",
"winston": "^2.3.0", "winston": "^2.4.2",
"ws": "^3.1.0", "ws": "^3.1.0",
"xml-stream": "^0.4.5" "xml-stream": "^0.4.5"
}, },