mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-27 00:05:15 +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:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user