Feat: use pg-promise notify for poller update

This commit is contained in:
csrapr 2021-05-25 17:40:22 +01:00 committed by Sérgio Salgado
parent 4ce4a32502
commit 121ced632e
2 changed files with 14 additions and 2 deletions

View file

@ -1,6 +1,7 @@
const _ = require('lodash/fp')
const db = require('./db')
const migration = require('./config-migration')
const { asyncLocalStorage } = require('./async-storage')
const OLD_SETTINGS_LOADER_SCHEMA_VERSION = 1
const NEW_SETTINGS_LOADER_SCHEMA_VERSION = 2
@ -73,7 +74,10 @@ function saveConfig (config) {
return loadLatestConfigOrNone()
.then(currentConfig => {
const newConfig = _.assign(currentConfig, config)
return db.none(configSql, ['config', { config: newConfig }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
return db.tx(t => {
return t.none(configSql, ['config', { config: newConfig }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(() => t.none('NOTIFY $1:name, $2', ['poller', asyncLocalStorage.getStore().get('schema')]))
}).catch(console.error)
})
}