1 | const Worker = require('./../class/Worker')
|
2 | const killWorkers = require('./../module/killWorkers')
|
3 | const log = require('./../module/log')
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 | module.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 | }
|