fix: prevent loop in case of logs with db down

This commit is contained in:
Rafael Taranto 2024-08-07 21:03:50 +01:00
parent dda217a29e
commit b9b532a633
2 changed files with 31 additions and 20 deletions

View file

@ -25,26 +25,30 @@ logger.info('Version: %s', version)
function run () {
const store = defaultStore()
return asyncLocalStorage.run(store, () => {
let count = 0
let handler
return new Promise((resolve, reject) => {
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))
.then(resolve)
})
.catch(errorHandler)
}
handler = setInterval(runner, 10000)
return runner()
runner()
handler = setInterval(runner, 10000)
})
})
}