1 | const Worker = require('./../class/Worker')
|
2 | const states = Worker.states
|
3 | const mergePorts = require('./../snippet/mergePorts')
|
4 | const AppStats = require('./../class/AppStats')
|
5 |
|
6 | module.exports = function list(config) {
|
7 | return new Promise(resolve => {
|
8 | const stats = {}
|
9 |
|
10 |
|
11 | config.apps.forEach(app => {
|
12 | stats[app.name] = new AppStats(app.dir)
|
13 | })
|
14 |
|
15 | Worker.workerList.forEach(worker => {
|
16 |
|
17 | if (!stats[worker.name]) {
|
18 | stats[worker.name] = new AppStats(worker.dir)
|
19 | }
|
20 |
|
21 | const appStats = stats[worker.name]
|
22 |
|
23 |
|
24 | const state = states[worker.state].toLowerCase()
|
25 | appStats[state]++
|
26 |
|
27 |
|
28 | appStats.ports = mergePorts(appStats.ports, worker.ports)
|
29 | })
|
30 |
|
31 | resolve({
|
32 | isResurrectable: global.isResurrectable,
|
33 | stats
|
34 | })
|
35 | })
|
36 | }
|