From 39c052e6bd15f32f1f2204d16f21a0cd4a46e6f5 Mon Sep 17 00:00:00 2001 From: Minzkraut Date: Thu, 1 Jun 2023 19:50:21 +0200 Subject: [PATCH] Handle node disconnection --- src/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index 0bc91e0..5fe7bd9 100644 --- a/src/index.js +++ b/src/index.js @@ -133,7 +133,6 @@ app.post("/jobs/:jobId/completed", async (req, res) => { res.status(400).send({ 'message': `Job ${jobId} not found` }); }); - wss.on('connection', function connection(ws) { var nodeID = uuid.v4(); ws.nodeID = nodeID; @@ -155,9 +154,13 @@ wss.on('connection', function connection(ws) { jobs['queued'][jobResult["jobId"]]['promise'].resolve(jobResult); } }); - + ws.on('close', function(reasonCode, description) { + console.log(`Node ${ws.nodeID} disconnected.`); + delete nodes[ws.nodeID] + }); }); + app.listen(PORT_WEB, () => { console.log(`Job Server API running on ${PORT_WEB}`); }) \ No newline at end of file