1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-06 03:50:04 +02:00

Don't allow the processor unit to run before we're able to connect to the database. This caused an issue when the database started up slowly, but the processor connected to the app/dev dealers regardless. Any received messages requiring database connectivity would cause the processor to die (and be restarted by systemd), causing lost messages on occasion.

This commit is contained in:
Simo Kinnunen 2017-02-06 00:36:32 +09:00
parent a995a2f823
commit 385acc4ff2
2 changed files with 18 additions and 2 deletions

View file

@ -101,6 +101,21 @@ db.connect = (function() {
}
})()
// Verifies that we can form a connection. Useful if it's necessary to make
// sure that a handler doesn't run at all if the database is on a break. In
// normal operation connections are formed lazily. In particular, this was
// an issue with the processor unit, as it started processing messages before
// it was actually truly able to save anything to the database. This lead to
// lost messages in certain situations.
db.ensureConnectivity = function(fn) {
return function() {
var args = [].slice.call(arguments)
return db.connect().then(function() {
return fn.apply(null, args)
})
}
}
// Close connection, we don't really care if it hasn't been created yet or not
db.close = function() {
return db.connect().then(function(conn) {

View file

@ -4,12 +4,13 @@ var logger = require('../../util/logger')
var wire = require('../../wire')
var wirerouter = require('../../wire/router')
var wireutil = require('../../wire/util')
var db = require('../../db')
var dbapi = require('../../db/api')
var lifecycle = require('../../util/lifecycle')
var srv = require('../../util/srv')
var zmqutil = require('../../util/zmqutil')
module.exports = function(options) {
module.exports = db.ensureConnectivity(function(options) {
var log = logger.createLogger('processor')
if (options.name) {
@ -241,4 +242,4 @@ module.exports = function(options) {
}
})
})
}
})