From b00033d36f1a89ce3be6246735004a1519e5f4a9 Mon Sep 17 00:00:00 2001 From: Maha Benzekri Date: Mon, 13 May 2024 08:40:37 +0200 Subject: [PATCH] wipppp --- CountItems/masterProcess.js | 4 +++- utils/monitoring.js | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CountItems/masterProcess.js b/CountItems/masterProcess.js index 23beab7f..c100be78 100644 --- a/CountItems/masterProcess.js +++ b/CountItems/masterProcess.js @@ -43,10 +43,12 @@ const countMaster = new CountMaster({ }); metricServer.onRequest((req, res) => monitoring.metricsHandler( - countMaster.stop.bind(countMaster), + countMaster, + () => process.exit(1), req, res, )); + const handleSignal = sig => countMaster.stop(sig, () => process.exit(0)); process.on('SIGINT', handleSignal); process.on('SIGHUP', handleSignal); diff --git a/utils/monitoring.js b/utils/monitoring.js index 4f1bf10d..76d949cf 100644 --- a/utils/monitoring.js +++ b/utils/monitoring.js @@ -68,7 +68,7 @@ function _writeResponse(res, error) { * @param {http.ServerResponse} res - http response object * @return {void} */ -async function metricsHandler(onScraped, req, res) { +async function metricsHandler(countMasterInstance, onScraped, req, res) { if (req.method !== 'GET' || req.url !== '/metrics') { return _writeResponse(res, errors.MethodNotAllowed); } @@ -88,7 +88,7 @@ async function metricsHandler(onScraped, req, res) { return _writeResponse(res, errors.MethodNotAllowed); } finally { if (CountMaster.waitingForPromScraping === true) { - onScraped(); + countMasterInstance.stop(null, onScraped); } } }