1
0
Fork 0
mirror of https://github.com/openstf/stf synced 2025-10-05 02:29:26 +02:00

Don't auto-migrate because it's slow when many processes have to do the same.

This commit is contained in:
Simo Kinnunen 2014-04-02 14:39:07 +09:00
parent 5183485a53
commit 8f90ce0e02
2 changed files with 131 additions and 97 deletions

View file

@ -435,6 +435,23 @@ program
}) })
}) })
program
.command('migrate')
.description('migrates the database to the latest version')
.action(function() {
var log = logger.createLogger('cli:migrate')
, db = require('./db')
db.setup()
.then(function() {
process.exit(0)
})
.catch(function(err) {
log.fatal('Migration had an error:', err.stack)
process.exit(1)
})
})
program program
.command('local [serial..]') .command('local [serial..]')
.description('start everything locally') .description('start everything locally')
@ -485,9 +502,15 @@ program
.option('-d, --disable-watch' .option('-d, --disable-watch'
, 'disable watching resources') , 'disable watching resources')
.action(function() { .action(function() {
var log = logger.createLogger('cli') var log = logger.createLogger('cli:local')
, options = cliutil.lastArg(arguments) , options = cliutil.lastArg(arguments)
, db = require('./db')
// Each forked process waits for signals to stop, and we run over the
// default limit of 10. So, it's not a leak, but a refactor wouldn't hurt.
process.setMaxListeners(20)
function run() {
var procs = [ var procs = [
// app triproxy // app triproxy
procutil.fork(__filename, [ procutil.fork(__filename, [
@ -582,7 +605,7 @@ program
log.info('Received SIGTERM, waiting for processes to terminate') log.info('Received SIGTERM, waiting for processes to terminate')
}) })
Promise.all(procs) return Promise.all(procs)
.then(function() { .then(function() {
process.exit(0) process.exit(0)
}) })
@ -593,6 +616,10 @@ program
process.exit(1) process.exit(1)
}) })
}) })
}
procutil.fork(__filename, ['migrate'])
.then(run)
}) })
program.parse(process.argv) program.parse(process.argv)

View file

@ -1,6 +1,7 @@
var setup = require('./setup') var setup = require('./setup')
var rutil = require('../util/rutil') var rutil = require('../util/rutil')
var logger = require('../util/logger') var logger = require('../util/logger')
var lifecycle = require('../util/lifecycle')
function connect() { function connect() {
var log = logger.createLogger('db') var log = logger.createLogger('db')
@ -11,11 +12,10 @@ function connect() {
, authKey: process.env.RDB_AUTHKEY , authKey: process.env.RDB_AUTHKEY
}) })
.then(function(conn) { .then(function(conn) {
conn.on('error', function(err) { return conn.on('error', function(err) {
log.fatal('Connection error', err.stack) log.fatal('Connection error', err.stack)
process.exit(1) lifecycle.fatal()
}) })
return setup(conn)
}) })
.catch(function(err) { .catch(function(err) {
log.fatal('Unable to connect to the database: "%s"', err.message) log.fatal('Unable to connect to the database: "%s"', err.message)
@ -46,3 +46,10 @@ db.run = function(q, options) {
return rutil.run(conn, q, options) return rutil.run(conn, q, options)
}) })
} }
// Sets up the database
db.setup = function() {
return db.connect().then(function(conn) {
return setup(conn)
})
}