router-services.js
1.23 KB
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
51
52
53
54
55
56
57
58
const MODULE_NAME = 'API-SERVER.ROUTER-SERVICES';
const express = require('express');
const logger = require('tektrans-logger');
const matrix = require('../matrix');
const router = express.Router();
module.exports = router;
function isPause(req, res) {
res.json({
method: '/services/is-pause',
error: null,
result: Boolean(matrix.paused)
});
}
function pause(req, res) {
matrix.paused = true;
res.json({
method: '/services/pause',
error: null,
result: Boolean(matrix.paused)
});
}
function resume(req, res) {
matrix.paused = false;
res.json({
method: '/services/resume',
error: null,
result: Boolean(matrix.paused)
});
}
function terminate(req, res) {
const { xid } = res.locals;
const delay = 5000;
res.json({
method: '/services/terminate',
error: null,
message: `Going to restart in ${delay} ms`
});
logger.info(`${MODULE_NAME} 9E1EC746: Got a terminate request. Going to restart`, { xid, delay })
setTimeout(() => {
process.exit(0);
}, delay);
}
router.get('/is-pause', isPause);
router.get('/pause', pause);
router.get('/resume', resume);
router.get('/terminate', terminate);