Skip to content

Commit

Permalink
Update Server status in Server power operations page
Browse files Browse the repository at this point in the history
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: #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 <[email protected]>
Signed-off-by: HuyLe <[email protected]>
  • Loading branch information
hieuhuynh-ampere committed Mar 5, 2024
1 parent 4700907 commit d821d69
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/store/modules/Operations/ControlStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
},
Expand Down

0 comments on commit d821d69

Please sign in to comment.