From d821d69c73cf0db77dc9d4711c7a77aff9b4ea9a Mon Sep 17 00:00:00 2001 From: Hieu Huynh Date: Wed, 28 Jun 2023 02:55:13 +0000 Subject: [PATCH] Update Server status in Server power operations page After reboot or shutdown CPU via WebUI, the Server status does not update. The current implementation uses setTimeout() with a timeout of 5 minutes, it means the server power operations page reloads after 5 minutes. The issue is that the power status has really changed but has not been updated on the Server status because of the timeout. Fix the issue by changing setTimeout() to setInterval(). The Server status is updated after each 5 seconds. Fixes: https://github.com/openbmc/webui-vue/issues/102 Reference: https://www.educba.com/settimeout-vs-setinterval/ Tested: 1. Power off the CPU via WebUI. 2. WebUI shows Server status as off and a power on button. Change-Id: I31359d970c2aa42f29115102ddbc9cbe85fb168d Signed-off-by: Hieu Huynh Signed-off-by: HuyLe --- src/store/modules/Operations/ControlStore.js | 13 ++++++++----- .../ServerPowerOperations/ServerPowerOperations.vue | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/store/modules/Operations/ControlStore.js b/src/store/modules/Operations/ControlStore.js index 9b8bf73dcc..022a49d37d 100644 --- a/src/store/modules/Operations/ControlStore.js +++ b/src/store/modules/Operations/ControlStore.js @@ -4,24 +4,27 @@ import i18n from '@/i18n'; /** * Watch for serverStatus changes in GlobalStore module * to set isOperationInProgress state - * Stop watching status changes and resolve Promise when - * serverStatus value matches passed argument or after 5 minutes + * Allows run get API from redfish function starting + * after the interval of 5 seconds time, then repeating continuously + * at that interval until serverStatus value matches passed argument + * then Stop watching status changes and resolve Promise. * @param {string} serverStatus * @returns {Promise} */ const checkForServerStatus = function (serverStatus) { return new Promise((resolve) => { - const timer = setTimeout(() => { + const timer = setInterval(() => { + this.dispatch('global/getSystemInfo'); resolve(); unwatch(); - }, 300000 /*5mins*/); + }, 5000); /*5seconds*/ const unwatch = this.watch( (state) => state.global.serverStatus, (value) => { if (value === serverStatus) { resolve(); unwatch(); - clearTimeout(timer); + clearInterval(timer); } } ); diff --git a/src/views/Operations/ServerPowerOperations/ServerPowerOperations.vue b/src/views/Operations/ServerPowerOperations/ServerPowerOperations.vue index ba9ebcedcb..80046f3c5f 100644 --- a/src/views/Operations/ServerPowerOperations/ServerPowerOperations.vue +++ b/src/views/Operations/ServerPowerOperations/ServerPowerOperations.vue @@ -205,6 +205,7 @@ export default { Promise.all([ this.$store.dispatch('serverBootSettings/getBootSettings'), this.$store.dispatch('controls/getLastPowerOperationTime'), + this.$store.dispatch('global/getSystemInfo'), bootSettingsPromise, ]).finally(() => this.endLoader()); },