Commit c6822da905f842cc0e72289f38dbab1199b2ac62
Exists in
master
Merge branch 'master' into 'master'
Master(efernandez) See merge request !43
Showing
2 changed files
Show diff stats
rutas/comprobantes.js
... | ... | @@ -45,11 +45,9 @@ router.post('/comprobante', function(req, res) { |
45 | 45 | // var recadv = require('../recadv')(JSON.parse(JSON.stringify(req.body.cabecera)), |
46 | 46 | // JSON.parse(JSON.stringify(req.body.cuerpo))); |
47 | 47 | |
48 | - var guardar = wsServer.guardarComprobante(req.body, req.body.cabecera.GLN); | |
48 | + wsServer.guardarComprobante(req.body, req.body.cabecera.GLN).then(() => { | |
49 | 49 | |
50 | - Promise.all([ | |
51 | - // recadv, | |
52 | - guardar, | |
50 | + Promise.all([ | |
53 | 51 | knex('PMAEFACT_TEMP').where({ |
54 | 52 | TIP: req.body.cabecera.TIP, |
55 | 53 | TCO: req.body.cabecera.TCO, |
... | ... | @@ -71,8 +69,9 @@ router.post('/comprobante', function(req, res) { |
71 | 69 | }) |
72 | 70 | .catch(err => { |
73 | 71 | console.log(err); |
74 | - console.log({data: 'error al guardar algo ruta comprobantes'}); | |
75 | - res.status(500).send(err) | |
72 | + res.status(500).send(err); | |
76 | 73 | }); |
74 | + }) | |
75 | + .catch((err) => res.status(500).send(err)); | |
77 | 76 | |
78 | 77 | }); |
webSocketServer/index.js
... | ... | @@ -9,9 +9,17 @@ module.exports = function() { |
9 | 9 | port: config.port |
10 | 10 | }); |
11 | 11 | |
12 | + function noop() {} | |
13 | + | |
14 | + function heartbeat() { | |
15 | + this.isAlive = true; | |
16 | + } | |
17 | + | |
12 | 18 | objWs.wsServer.on('connection', function connection(ws) { |
13 | 19 | |
14 | 20 | console.log('open socket server'); |
21 | + ws.isAlive = true; | |
22 | + ws.on('pong', heartbeat); | |
15 | 23 | |
16 | 24 | ws.on('message', function incoming(message) { |
17 | 25 | |
... | ... | @@ -27,6 +35,15 @@ module.exports = function() { |
27 | 35 | }); |
28 | 36 | }); |
29 | 37 | |
38 | + const interval = setInterval(function ping() { | |
39 | + objWs.wsServer.clients.forEach(function each(ws) { | |
40 | + if (ws.isAlive === false) return ws.terminate(); | |
41 | + | |
42 | + ws.isAlive = false; | |
43 | + ws.ping(noop); | |
44 | + }); | |
45 | + }, 10000); | |
46 | + | |
30 | 47 | objWs.getEntidad = function(gln, tableName, where, queryString) { |
31 | 48 | |
32 | 49 | return new Promise(function(resolve, reject) { |