fix: concurrency issues caused by poller
This commit is contained in:
parent
7307466df4
commit
6b7d14de2b
7 changed files with 48 additions and 26 deletions
|
|
@ -16,7 +16,6 @@ const settingsLoader = require('./new-settings-loader')
|
|||
const NodeCache = require('node-cache')
|
||||
const util = require('util')
|
||||
const db = require('./db')
|
||||
const state = require('./middlewares/state')
|
||||
const processBatches = require('./tx-batching-processing')
|
||||
|
||||
const INCOMING_TX_INTERVAL = 30 * T.seconds
|
||||
|
|
@ -99,8 +98,8 @@ function reload (schema) {
|
|||
})
|
||||
}
|
||||
|
||||
function pi () { return cachedVariables.get(asyncLocalStorage.getStore().get('schema')).pi }
|
||||
function settings () { return cachedVariables.get(asyncLocalStorage.getStore().get('schema')).settings }
|
||||
function pi () { return cachedVariables.get('public').pi }
|
||||
function settings () { return cachedVariables.get('public').settings }
|
||||
|
||||
function initialSanctionsDownload () {
|
||||
const structs = sanctions.getStructs()
|
||||
|
|
@ -146,19 +145,39 @@ function initializeEachSchema (schemas = ['public']) {
|
|||
}, schemas)
|
||||
}
|
||||
|
||||
function recursiveTimeout (func, timeout, ...vars) {
|
||||
setTimeout(() => {
|
||||
let promise = null
|
||||
|
||||
const loadVariables = vars.length > 0 && typeof vars[0] === 'function'
|
||||
if (loadVariables) {
|
||||
const funcVars = [...vars]
|
||||
funcVars[0] = vars[0]()
|
||||
promise = func(...funcVars)
|
||||
} else {
|
||||
promise = func(...vars)
|
||||
}
|
||||
|
||||
promise.finally(() => {
|
||||
recursiveTimeout(func, timeout, ...vars)
|
||||
})
|
||||
}, timeout)
|
||||
}
|
||||
|
||||
function addToQueue (func, interval, schema, queue, ...vars) {
|
||||
return schemaCallbacks.get(schema).push(setInterval(() => {
|
||||
return queue.enqueue().then(() => {
|
||||
// get plugins or settings from the cache every time func is run
|
||||
const loadVariables = vars.length > 0 && typeof vars[0] === 'function'
|
||||
if (loadVariables) {
|
||||
const funcVars = [...vars]
|
||||
funcVars[0] = vars[0]()
|
||||
return func(...funcVars)
|
||||
}
|
||||
return func(...vars)
|
||||
}).catch(console.error)
|
||||
}, interval))
|
||||
recursiveTimeout(func, interval, ...vars)
|
||||
// return schemaCallbacks.get(schema).push(setInterval(() => {
|
||||
// return queue.enqueue().then(() => {
|
||||
// // get plugins or settings from the cache every time func is run
|
||||
// const loadVariables = vars.length > 0 && typeof vars[0] === 'function'
|
||||
// if (loadVariables) {
|
||||
// const funcVars = [...vars]
|
||||
// funcVars[0] = vars[0]()
|
||||
// return func(...funcVars)
|
||||
// }
|
||||
// return func(...vars)
|
||||
// }).catch(console.error)
|
||||
// }, interval))
|
||||
}
|
||||
|
||||
function doPolling (schema) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue