serverapm2.js
967 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const bb = require('bluebird');
const compose = require('koa-compose');
const logger = global.yoho.logger;
const {
handleErrorReport,
handleProcessInfo,
handleWebServerDuration,
handleAlertInfo
} = require('./serverapm-service2');
const riskService = require('./risk-service/index2');
const handleRisk = riskService();
const handlers = compose([
handleWebServerDuration,
handleRisk,
handleErrorReport,
handleProcessInfo,
handleAlertInfo
]);
const server = {
async handle(msgs) {
try {
await bb.map(msgs, async(m) => {
if (!m.type) {
return;
}
await handlers(m);
}, {concurrency: 2});
logger.debug('[server] handle OK [%j]', msgs);
} catch (e) {
logger.error('[server] all handle ERROR [%s]', e);
}
}
};
module.exports = function(req, res) {
let data = req.body || {};
server.handle(data).catch(err => {
logger.error(err);
});
res.status(204).json();
};