mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-19 00:23:25 +02:00
Move support plugins to their own folder.
This commit is contained in:
38
lib/roles/device/support/quit.js
Normal file
38
lib/roles/device/support/quit.js
Normal file
@@ -0,0 +1,38 @@
|
||||
var Promise = require('bluebird')
|
||||
var syrup = require('syrup')
|
||||
|
||||
var logger = require('../../../util/logger')
|
||||
|
||||
module.exports = syrup()
|
||||
.define(function(options) {
|
||||
var log = logger.createLogger('device:plugins:quit')
|
||||
var cleanup = []
|
||||
|
||||
function graceful() {
|
||||
log.info('Winding down for graceful exit')
|
||||
|
||||
var wait = Promise.all(cleanup.map(function(fn) {
|
||||
return fn()
|
||||
}))
|
||||
|
||||
return wait.then(function() {
|
||||
process.exit(0)
|
||||
})
|
||||
}
|
||||
|
||||
function fatal() {
|
||||
log.fatal('Shutting down due to fatal error')
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
process.on('SIGINT', graceful)
|
||||
process.on('SIGTERM', graceful)
|
||||
|
||||
return {
|
||||
graceful: graceful
|
||||
, fatal: fatal
|
||||
, observe: function(promise) {
|
||||
cleanup.push(promise)
|
||||
}
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user