diff --git a/src/modules/TileConsts.js b/src/modules/TileConsts.js index 554f1fd1e29f9a81d135d9a3959273ed6e8d477d..163f52ede78df8c02a1812fb7512e959f9b9c3fe 100644 --- a/src/modules/TileConsts.js +++ b/src/modules/TileConsts.js @@ -1,6 +1,6 @@ /* eslint-disable no-magic-numbers, max-len */ -import { SEPARATOR_OPTION } from './Consts.js'; +import { MS_PER_SECOND, SEPARATOR_OPTION } from './Consts.js'; /* Tiles */ @@ -596,3 +596,7 @@ export const centerSymbolLabelMaxLen = 22; export const TILES_PER_PAGE = 4; export const MAX_PAGES = 10; export const MAX_NORMAL_TILES_ALLOWED = MAX_PAGES === 1 ? TILES_PER_PAGE : (TILES_PER_PAGE - 1) * MAX_PAGES; + +/* Queue */ + +export const AFTER_SAVE_DELAY = 19 * MS_PER_SECOND; // ~20 s in practice, multiple of status refresh delay \ No newline at end of file diff --git a/src/store/modules/devices/Actions.js b/src/store/modules/devices/Actions.js index 33922c8c5ac94c7ae13b64241139f8ec7a8a437e..88f1774c6d42c65e16a266ac6940d6db99420dfd 100644 --- a/src/store/modules/devices/Actions.js +++ b/src/store/modules/devices/Actions.js @@ -3,6 +3,7 @@ import { prepareErrorDetails } from '../../../vue-reusables/modules/Utils.js'; import { c } from '../../../vue-reusables/modules/Log.js'; import { MS_PER_SECOND, READOUT_STATUS_PATH, backendApi, REMOVE_MSG_AFTER, REBOOT_DURATION, REBOOT_PROGRESS_INTERVAL } from '../../../modules/Consts.js'; import { roundSensorValue, isUluxDevice, isPrimaryDevice, dsuidFromIndex } from './Helpers.js'; +import { AFTER_SAVE_DELAY } from '../../../modules/TileConsts.js'; export default { fetchSubDevices: (context, dsuids) => { @@ -197,7 +198,8 @@ export default { operationsInProgress[dsuid] = operationsInProgress[dsuid] || 0; operationsCompleted[dsuid] = operationsCompleted[dsuid] || 0; const inProgress = operationsInProgress[dsuid] > 0; - context.commit('setStatus', { + + const setStatus = () => context.commit('setStatus', { dsuid, status: { inProgress, @@ -207,6 +209,24 @@ export default { errorCount: errorCounts[dsuid] } }); + // delay setting "non-busy anymore" status after tile save, to make up for 10s gap between + // queue emptied and actual device status (device is still busy) and cache update + // (old tile config is still in property tree, only updated after ~10 s from when queue is emptied): + if (context.state.statusDelays[dsuid] != null) { + if (context.state.statusDelays[dsuid]) { // if it's a timestamp + if (new Date().getTime() >= context.state.statusDelays[dsuid]) { + setStatus(); + context.commit('setStatusDelay', { dsuid, delayTill: null }); + } + } else if (context.state.statuses[dsuid].inProgress && !inProgress) { // if it's 0 - meaning: need timestamp of when saving finished, to then delay from that point in time + context.commit('setStatusDelay', { dsuid, delayTill: new Date().getTime() + AFTER_SAVE_DELAY }); + } else { + setStatus(); + } + } else { + setStatus(); + } + // check if first readout is done DsAxios.get('/json/property/query2', { params: { diff --git a/src/store/modules/devices/Mutations.js b/src/store/modules/devices/Mutations.js index 550628002c4891662c899c24cdc2dd4a0fe865a1..d27ad3e2c3ff408a1270a37c5386c004a710651d 100644 --- a/src/store/modules/devices/Mutations.js +++ b/src/store/modules/devices/Mutations.js @@ -39,6 +39,9 @@ export default { setStatus: (state, { dsuid, status }) => { Vue.set(state.statuses, dsuid, status); }, + setStatusDelay: (state, { dsuid, delayTill }) => { + Vue.set(state.statusDelays, dsuid, delayTill); + }, setErrorCount: (state, { dsuid, count }) => { Vue.set(state.errorCounts, dsuid, count); }, diff --git a/src/store/modules/devices/State.js b/src/store/modules/devices/State.js index 8a7f8c4df92012c5ad9bf702b28f3b9c86293102..f52e61287b4e6fd30c80b2580a83e4e184c2a7c7 100644 --- a/src/store/modules/devices/State.js +++ b/src/store/modules/devices/State.js @@ -2,6 +2,7 @@ export default { primaryDevices: null, // object, dsuid as key subDevices: null, // object, dsuid as key statuses: {}, // object, dsuid as key + statusDelays: {}, // object, dsuid as key errorCounts: {}, // object, dsuid as key rebootingStatuses: {}, // object, dsuid as key firstReadoutsDone: {}, // object, dsuid as key diff --git a/src/store/modules/tiles/Actions.js b/src/store/modules/tiles/Actions.js index 93a77ccb6844f86d41d1e15162472f96bb0c2e04..a597e0aac087c7ce4b78f7cbcceef125c8a4982c 100644 --- a/src/store/modules/tiles/Actions.js +++ b/src/store/modules/tiles/Actions.js @@ -227,6 +227,7 @@ export default { // this isn't needed any more really, as the user is taken back to the home page, but just to be on the safe side: context.commit('setInitialHash', makeHash({ pages: context.state.pages, tiles: context.state.tiles, centerSymbols: context.state.centerSymbols })); context.commit('setSaving', false); + context.commit('devices/setStatusDelay', { dsuid: context.state.dsuid, delayTill: 0 }, { root: true }); // subscribe to 'finish' event - otherwise it would wait in a queue and would be // returned from backend on first occasion (whenever some next subscription happens);