From 3fc90e188aaba84daff87fd1a5265000f15b42a0 Mon Sep 17 00:00:00 2001 From: Rafael Taranto Date: Thu, 10 Jul 2025 10:10:59 +0100 Subject: [PATCH] fix: batch diagnostics --- .../lib/middlewares/populateSettings.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/server/lib/middlewares/populateSettings.js b/packages/server/lib/middlewares/populateSettings.js index 8d6c9d0b..e9a3a895 100644 --- a/packages/server/lib/middlewares/populateSettings.js +++ b/packages/server/lib/middlewares/populateSettings.js @@ -33,37 +33,44 @@ function machineAction(type, value) { logger.debug( `Rebooting machine '${deviceId}' from operator ${operatorId}`, ) - state.reboots[operatorId] = { [deviceId]: pid } + if (!state.reboots[operatorId]) state.reboots[operatorId] = {} + state.reboots[operatorId][deviceId] = pid break case 'shutdown': logger.debug( `Shutting down machine '${deviceId}' from operator ${operatorId}`, ) - state.shutdowns[operatorId] = { [deviceId]: pid } + if (!state.shutdowns[operatorId]) state.shutdowns[operatorId] = {} + state.shutdowns[operatorId][deviceId] = pid break case 'restartServices': logger.debug( `Restarting services of machine '${deviceId}' from operator ${operatorId}`, ) - state.restartServicesMap[operatorId] = { [deviceId]: pid } + if (!state.restartServicesMap[operatorId]) + state.restartServicesMap[operatorId] = {} + state.restartServicesMap[operatorId][deviceId] = pid break case 'emptyUnit': logger.debug( `Emptying units from machine '${deviceId}' from operator ${operatorId}`, ) - state.emptyUnit[operatorId] = { [deviceId]: pid } + if (!state.emptyUnit[operatorId]) state.emptyUnit[operatorId] = {} + state.emptyUnit[operatorId][deviceId] = pid break case 'refillUnit': logger.debug( `Refilling recyclers from machine '${deviceId}' from operator ${operatorId}`, ) - state.refillUnit[operatorId] = { [deviceId]: pid } + if (!state.refillUnit[operatorId]) state.refillUnit[operatorId] = {} + state.refillUnit[operatorId][deviceId] = pid break case 'diagnostics': logger.debug( `Running diagnostics on machine '${deviceId}' from operator ${operatorId}`, ) - state.diagnostics[operatorId] = { [deviceId]: pid } + if (!state.diagnostics[operatorId]) state.diagnostics[operatorId] = {} + state.diagnostics[operatorId][deviceId] = pid break default: break