UNPKG

1.04 kBJavaScriptView Raw
1const Worker = require('./../class/Worker')
2const killWorkers = require('./../module/killWorkers')
3const log = require('./../module/log')
4
5/*
6command {
7 app,
8 timeout
9}
10*/
11
12module.exports = function stop(config, command) {
13 return new Promise((resolve, reject) => {
14 const app = config.apps.find(app => app.name === command.app)
15
16 let timeout = (app && app.env.NODE_ENV !== 'development') ? 30e3 : 0
17
18 if (command.opt.timeout) {
19 if (isNaN(+command.opt.timeout)) {
20 timeout = null
21 } else {
22 timeout = +command.opt.timeout
23 }
24 }
25
26 const workers = Worker.workerList.filter(worker => worker.name === command.app)
27 const killed = killWorkers(workers, timeout, command.opt.signal)
28
29 killed.then(() => {
30 let i = config.apps.findIndex(app => app.name === command.app)
31
32 if (i !== -1) {
33 log.remove(config.apps[i].name)
34 config.apps.splice(i, 1)
35 }
36
37 resolve({
38 app: command.app,
39 killed: workers.length
40 })
41 }).catch(reject)
42 })
43}