mirror of
https://github.com/openstf/stf
synced 2025-10-05 10:39:25 +02:00
Don't auto-migrate because it's slow when many processes have to do the same.
This commit is contained in:
parent
5183485a53
commit
8f90ce0e02
2 changed files with 131 additions and 97 deletions
215
lib/cli.js
215
lib/cli.js
|
@ -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,114 +502,124 @@ 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')
|
||||||
|
|
||||||
var procs = [
|
// Each forked process waits for signals to stop, and we run over the
|
||||||
// app triproxy
|
// default limit of 10. So, it's not a leak, but a refactor wouldn't hurt.
|
||||||
procutil.fork(__filename, [
|
process.setMaxListeners(20)
|
||||||
'triproxy', 'app001'
|
|
||||||
, '--bind-pub', options.bindAppPub
|
|
||||||
, '--bind-dealer', options.bindAppDealer
|
|
||||||
, '--bind-pull', options.bindAppPull
|
|
||||||
])
|
|
||||||
|
|
||||||
// device triproxy
|
function run() {
|
||||||
, procutil.fork(__filename, [
|
var procs = [
|
||||||
'triproxy', 'dev001'
|
// app triproxy
|
||||||
, '--bind-pub', options.bindDevPub
|
procutil.fork(__filename, [
|
||||||
, '--bind-dealer', options.bindDevDealer
|
'triproxy', 'app001'
|
||||||
, '--bind-pull', options.bindDevPull
|
, '--bind-pub', options.bindAppPub
|
||||||
])
|
, '--bind-dealer', options.bindAppDealer
|
||||||
|
, '--bind-pull', options.bindAppPull
|
||||||
|
])
|
||||||
|
|
||||||
// processor one
|
// device triproxy
|
||||||
, procutil.fork(__filename, [
|
, procutil.fork(__filename, [
|
||||||
'processor', 'proc001'
|
'triproxy', 'dev001'
|
||||||
, '--connect-app-dealer', options.bindAppDealer
|
, '--bind-pub', options.bindDevPub
|
||||||
, '--connect-dev-dealer', options.bindDevDealer
|
, '--bind-dealer', options.bindDevDealer
|
||||||
])
|
, '--bind-pull', options.bindDevPull
|
||||||
|
])
|
||||||
|
|
||||||
// processor two
|
// processor one
|
||||||
, procutil.fork(__filename, [
|
, procutil.fork(__filename, [
|
||||||
'processor', 'proc002'
|
'processor', 'proc001'
|
||||||
, '--connect-app-dealer', options.bindAppDealer
|
, '--connect-app-dealer', options.bindAppDealer
|
||||||
, '--connect-dev-dealer', options.bindDevDealer
|
, '--connect-dev-dealer', options.bindDevDealer
|
||||||
])
|
])
|
||||||
|
|
||||||
// reaper one
|
// processor two
|
||||||
, procutil.fork(__filename, [
|
, procutil.fork(__filename, [
|
||||||
'reaper', 'reaper001'
|
'processor', 'proc002'
|
||||||
, '--connect-push', options.bindDevPull
|
, '--connect-app-dealer', options.bindAppDealer
|
||||||
])
|
, '--connect-dev-dealer', options.bindDevDealer
|
||||||
|
])
|
||||||
|
|
||||||
// provider
|
// reaper one
|
||||||
, procutil.fork(__filename, [
|
, procutil.fork(__filename, [
|
||||||
'provider'
|
'reaper', 'reaper001'
|
||||||
, '--name', options.provider
|
, '--connect-push', options.bindDevPull
|
||||||
, '--connect-sub', options.bindDevPub
|
])
|
||||||
, '--connect-push', options.bindDevPull
|
|
||||||
].concat(cliutil.allUnknownArgs(arguments)))
|
|
||||||
|
|
||||||
// auth-mock
|
// provider
|
||||||
, procutil.fork(__filename, [
|
, procutil.fork(__filename, [
|
||||||
'auth-mock'
|
'provider'
|
||||||
, '--port', options.authPort
|
, '--name', options.provider
|
||||||
, '--secret', options.authSecret
|
, '--connect-sub', options.bindDevPub
|
||||||
, '--app-url', util.format('http://localhost:%d/', options.appPort)
|
, '--connect-push', options.bindDevPull
|
||||||
])
|
].concat(cliutil.allUnknownArgs(arguments)))
|
||||||
|
|
||||||
// app
|
// auth-mock
|
||||||
, procutil.fork(__filename, [
|
, procutil.fork(__filename, [
|
||||||
'app'
|
'auth-mock'
|
||||||
, '--port', options.appPort
|
, '--port', options.authPort
|
||||||
, '--secret', options.authSecret
|
, '--secret', options.authSecret
|
||||||
, '--auth-url', util.format('http://localhost:%d/', options.authPort)
|
, '--app-url', util.format('http://localhost:%d/', options.appPort)
|
||||||
, '--storage-url'
|
])
|
||||||
, util.format('http://localhost:%d/', options.storagePort)
|
|
||||||
, '--connect-sub', options.bindAppPub
|
|
||||||
, '--connect-push', options.bindAppPull
|
|
||||||
].concat((function() {
|
|
||||||
var extra = []
|
|
||||||
if (options.disableWatch) {
|
|
||||||
extra.push('--disable-watch')
|
|
||||||
}
|
|
||||||
return extra
|
|
||||||
})()))
|
|
||||||
|
|
||||||
// storage
|
// app
|
||||||
, procutil.fork(__filename, [
|
, procutil.fork(__filename, [
|
||||||
'storage-temp'
|
'app'
|
||||||
, '--port', options.storagePort
|
, '--port', options.appPort
|
||||||
])
|
, '--secret', options.authSecret
|
||||||
]
|
, '--auth-url', util.format('http://localhost:%d/', options.authPort)
|
||||||
|
, '--storage-url'
|
||||||
|
, util.format('http://localhost:%d/', options.storagePort)
|
||||||
|
, '--connect-sub', options.bindAppPub
|
||||||
|
, '--connect-push', options.bindAppPull
|
||||||
|
].concat((function() {
|
||||||
|
var extra = []
|
||||||
|
if (options.disableWatch) {
|
||||||
|
extra.push('--disable-watch')
|
||||||
|
}
|
||||||
|
return extra
|
||||||
|
})()))
|
||||||
|
|
||||||
function shutdown() {
|
// storage
|
||||||
log.info('Shutting down all child processes')
|
, procutil.fork(__filename, [
|
||||||
procs.forEach(function(proc) {
|
'storage-temp'
|
||||||
proc.cancel()
|
, '--port', options.storagePort
|
||||||
|
])
|
||||||
|
]
|
||||||
|
|
||||||
|
function shutdown() {
|
||||||
|
log.info('Shutting down all child processes')
|
||||||
|
procs.forEach(function(proc) {
|
||||||
|
proc.cancel()
|
||||||
|
})
|
||||||
|
return Promise.settle(procs)
|
||||||
|
}
|
||||||
|
|
||||||
|
process.on('SIGINT', function() {
|
||||||
|
log.info('Received SIGINT, waiting for processes to terminate')
|
||||||
})
|
})
|
||||||
return Promise.settle(procs)
|
|
||||||
|
process.on('SIGTERM', function() {
|
||||||
|
log.info('Received SIGTERM, waiting for processes to terminate')
|
||||||
|
})
|
||||||
|
|
||||||
|
return Promise.all(procs)
|
||||||
|
.then(function() {
|
||||||
|
process.exit(0)
|
||||||
|
})
|
||||||
|
.catch(function(err) {
|
||||||
|
log.fatal('Child process had an error', err.stack)
|
||||||
|
return shutdown()
|
||||||
|
.then(function() {
|
||||||
|
process.exit(1)
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
process.on('SIGINT', function() {
|
procutil.fork(__filename, ['migrate'])
|
||||||
log.info('Received SIGINT, waiting for processes to terminate')
|
.then(run)
|
||||||
})
|
|
||||||
|
|
||||||
process.on('SIGTERM', function() {
|
|
||||||
log.info('Received SIGTERM, waiting for processes to terminate')
|
|
||||||
})
|
|
||||||
|
|
||||||
Promise.all(procs)
|
|
||||||
.then(function() {
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
.catch(function(err) {
|
|
||||||
log.fatal('Child process had an error', err.stack)
|
|
||||||
return shutdown()
|
|
||||||
.then(function() {
|
|
||||||
process.exit(1)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
program.parse(process.argv)
|
program.parse(process.argv)
|
||||||
|
|
|
@ -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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue