Feat: AsyncLocalStorage for schema changing

This commit is contained in:
csrapr 2021-03-02 16:22:35 +00:00 committed by Josh Harvey
parent e6059be8d2
commit 351d170c31
5 changed files with 55 additions and 27 deletions

View file

@ -3,6 +3,7 @@ const http = require('http')
const https = require('https')
const argv = require('minimist')(process.argv.slice(2))
const { asyncLocalStorage, defaultStore } = require('./async-storage')
const routes = require('./routes')
const logger = require('./logger')
const poller = require('./poller')
@ -19,26 +20,29 @@ const version = require('../package.json').version
logger.info('Version: %s', version)
function run () {
let count = 0
let handler
const store = defaultStore()
return asyncLocalStorage.run(store, () => {
let count = 0
let handler
const errorHandler = err => {
count += 1
logger.error(err)
logger.error('[%d] Retrying in 10s...', count)
}
const errorHandler = err => {
count += 1
logger.error(err)
logger.error('[%d] Retrying in 10s...', count)
}
const runner = () =>
settingsLoader.loadLatest()
.then(settings => {
clearInterval(handler)
return loadSanctions(settings)
.then(() => startServer(settings))
})
.catch(errorHandler)
const runner = () =>
settingsLoader.loadLatest()
.then(settings => {
clearInterval(handler)
return loadSanctions(settings)
.then(() => startServer(settings))
})
.catch(errorHandler)
handler = setInterval(runner, 10000)
return runner()
handler = setInterval(runner, 10000)
return runner()
})
}
function loadSanctions (settings) {