Skip to content

Commit

Permalink
Merge pull request #583 from erwindon/timers-off
Browse files Browse the repository at this point in the history
timers are not always stopped when leaving a page
  • Loading branch information
erwindon authored Nov 2, 2024
2 parents 3f3571a + 32587a9 commit 2a07c05
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 32 deletions.
16 changes: 9 additions & 7 deletions saltgui/static/scripts/issues/State.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,39 +65,41 @@ export class StateIssues extends Issues {
jobs = jobs.slice(0, MAX_HIGHSTATE_JOBS);
}

this.jobs = jobs;
pPanel.jobs = jobs;
// this is good only while "State" is the only issue-provider that uses play/pause
pPanel.setPlayPauseButton(jobs.length === 0 ? "none" : "play");

this._updateNextJob(pPanel, pMsg, pKeys);
}

_updateNextJob (pPanel, pMsg, pKeys) {
if (!this.jobs) {
if (!pPanel.jobs) {
return;
}
if (!this.jobs.length) {
if (!pPanel.jobs.length) {
// this is good only while "State" is the only issue-provider
pPanel.setPlayPauseButton("none");
this.jobs = null;
pPanel.jobs = null;
Issues.readyCategory(pPanel, pMsg);
return;
}

if (pPanel.playOrPause !== "play") {
window.setTimeout(() => {
pPanel.issuesStateTimeout = window.setTimeout(() => {
pPanel.issuesStateTimeout = null;
this._updateNextJob(pPanel, pMsg, pKeys);
}, 1000);
return;
}

const job = this.jobs.pop();
const job = pPanel.jobs.pop();

const runnerJobsListJobPromise = this.api.getRunnerJobsListJob(job.id);

runnerJobsListJobPromise.then((pRunnerJobsListJobData) => {
StateIssues._handleJobRunnerJobsListJob(pPanel, pRunnerJobsListJobData, pKeys);
window.setTimeout(() => {
pPanel.issuesStateTimeout = window.setTimeout(() => {
pPanel.issuesStateTimeout = null;
this._updateNextJob(pPanel, pMsg, pKeys);
}, 100);
return true;
Expand Down
4 changes: 4 additions & 0 deletions saltgui/static/scripts/pages/HighState.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ export class HighStatePage extends Page {
this.jobs.handleSaltJobRetEvent(pData);
}
}

onHide () {
this.highstate.onHide();
}
}
4 changes: 4 additions & 0 deletions saltgui/static/scripts/pages/Issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@ export class IssuesPage extends Page {
this.jobs.handleSaltJobRetEvent(pData);
}
}

onHide () {
this.issues.onHide();
}
}
4 changes: 4 additions & 0 deletions saltgui/static/scripts/pages/Job.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ export class JobPage extends Page {
handleSaltJobRetEvent (pData) {
this.job.handleSaltJobRetEvent(pData);
}

onHide () {
this.job.onHide();
}
}
4 changes: 4 additions & 0 deletions saltgui/static/scripts/pages/Jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@ export class JobsPage extends Page {
handleSaltJobRetEvent (pData) {
this.jobs.handleSaltJobRetEvent(pData);
}

onHide () {
this.jobs.onHide();
}
}
8 changes: 4 additions & 4 deletions saltgui/static/scripts/pages/Logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class LogoutPage extends Page {
onRegister () {
// don't verify for invalid sessions too often
// this happens only when the server was reset
this.logoutTimer = window.setInterval(() => {
this.logoutInterval = window.setInterval(() => {
this._logoutTimer();
}, 60000);

Expand Down Expand Up @@ -51,9 +51,9 @@ export class LogoutPage extends Page {
// not to any regular api functions
// may happen due to https://github.com/saltstack/salt/issues/59620
// repeating this is not so useful
if (this.logoutTimer) {
clearInterval(this.logoutTimer);
this.logoutTimer = null;
if (this.logoutInterval) {
clearInterval(this.logoutInterval);
this.logoutInterval = null;
}
return;
}
Expand Down
4 changes: 4 additions & 0 deletions saltgui/static/scripts/pages/Nodegroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ export class NodegroupsPage extends Page {
const nodegroups = Utils.getStorageItemObject("session", "nodegroups");
return Object.keys(nodegroups).length > 0;
}

onHide () {
this.nodegroups.onHide();
}
}
11 changes: 10 additions & 1 deletion saltgui/static/scripts/panels/HighState.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,14 @@ export class HighStatePanel extends Panel {
});
}

onHide () {
if (this.nextJobTimeout) {
// stop the timer when nobody is looking
window.clearTimeout(this.nextJobTimeout);
this.nextJobTimeout = null;
}
}

_addMenuItemStateApply (pMenu, pMinionId) {
pMenu.addMenuItem("Apply state...", () => {
const cmdArr = ["state.apply"];
Expand Down Expand Up @@ -205,7 +213,8 @@ export class HighStatePanel extends Panel {
this._handleJob(job);
}

window.setTimeout(() => {
this.nextJobTimeout = window.setTimeout(() => {
this.nextJobTimeout = null;
this._updateNextJob();
}, 1000);
}
Expand Down
11 changes: 11 additions & 0 deletions saltgui/static/scripts/panels/Issues.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,15 @@ export class IssuesPanel extends Panel {
Utils.addToolTip(this.msgDiv, pErrorMsg);
});
}

onHide () {
// from StateIssues
this.jobs = null;

if (this.issuesStateTimeout) {
// stop the timer when nobody is looking
window.clearTimeout(this.issuesStateTimeout);
this.issuesStateTimeout = null;
}
}
}
11 changes: 10 additions & 1 deletion saltgui/static/scripts/panels/Job.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ export class JobPanel extends Panel {
return;
}

window.setTimeout(() => {
this.refreshJobTimeout = window.setTimeout(() => {
this.refreshJobTimeout = null;
if (this.playOrPause === "play") {
this.onShow();
} else {
Expand Down Expand Up @@ -118,6 +119,14 @@ export class JobPanel extends Panel {
this.setPlayPauseButton(jobRefresh);
}

onHide () {
if (this.refreshJobTimeout) {
// stop the timer when nobody is looking
window.clearTimeout(this.refreshJobTimeout);
this.refreshJobTimeout = null;
}
}

static _isResultOk (result) {
if (!result.success) {
return false;
Expand Down
9 changes: 9 additions & 0 deletions saltgui/static/scripts/panels/JobsDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ export class JobsDetailsPanel extends JobsPanel {
super.onShow(cnt);
}

onHide () {
if (this.updateNextJobInterval) {
// stop the timer when nobody is looking
window.clearInterval(this.updateNextJobInterval);
this.updateNextJobInterval = null;
}
}

jobsListIsReady () {
this.nrErrors = 0;

Expand Down Expand Up @@ -185,6 +193,7 @@ export class JobsDetailsPanel extends JobsPanel {
// only update one item at a time
return;
}

if (!workLeft) {
this.setPlayPauseButton("none");
this.updateFooter();
Expand Down
17 changes: 14 additions & 3 deletions saltgui/static/scripts/panels/Nodegroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ export class NodegroupsPanel extends Panel {

localGrainsItemsPromise.then((pLocalGrainsItemsData) => {
this.updateMinions(pLocalGrainsItemsData);
window.setTimeout(() => {
this.nodeGroupTimeout = window.setTimeout(() => {
this.nodeGroupTimeout = null;
this._handleStep(pWheelKeyListAllData.return[0].data.return);
}, 100);
return true;
Expand All @@ -61,6 +62,14 @@ export class NodegroupsPanel extends Panel {
});
}

onHide () {
if (this.nodeGroupTimeout) {
// stop the timer when nobody is looking
window.clearTimeout(this.nodeGroupTimeout);
this.nodeGroupTimeout = null;
}
}

updateFooter () {
const nodegroups = Utils.getStorageItemObject("session", "nodegroups");
const txt = ", " + Utils.txtZeroOneMany(Object.keys(nodegroups).length,
Expand Down Expand Up @@ -222,7 +231,8 @@ export class NodegroupsPanel extends Panel {
titleElement.innerHTML = titleElement.innerHTML.replace("(loading)", txt);

// try again for more
window.setTimeout(() => {
this.nodeGroupTimeout = window.setTimeout(() => {
this.nodeGroupTimeout = null;
this._handleStep(pWheelKeyListAllSimpleData);
}, 100);
}, (pLocalTestVersionMsg) => {
Expand Down Expand Up @@ -271,7 +281,8 @@ export class NodegroupsPanel extends Panel {
// system can decide to remove the play/pause button
if (this.playOrPause !== "play") {
// try again later for more
window.setTimeout(() => {
this.nodeGroupTimeout = window.setTimeout(() => {
this.nodeGroupTimeout = null;
this._handleStep(pWheelKeyListAllSimpleData);
}, 100);
return;
Expand Down
18 changes: 9 additions & 9 deletions saltgui/static/scripts/panels/Options.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,6 @@ export class OptionsPanel extends Panel {
}
}

onHide () {
if (this.updateExpiresTimer) {
// stop the timer when noone is looking
window.clearInterval(this.updateExpiresTimer);
this.updateExpiresTimer = null;
}
}

onShow () {
// build the controls for all options
for (const option of this.options) {
Expand Down Expand Up @@ -332,7 +324,7 @@ export class OptionsPanel extends Panel {
}

if (category === "session" && name === "expire") {
this.updateExpiresTimer = window.setInterval(() => {
this.updateExpiresInterval = window.setInterval(() => {
// just redo the whole text-block
OptionsPanel._enhanceSessionExpire(td, value, sessionStart);
}, 1000);
Expand Down Expand Up @@ -377,6 +369,14 @@ export class OptionsPanel extends Panel {
}
}

onHide () {
if (this.updateExpiresInterval) {
// stop the timer when nobody is looking
window.clearInterval(this.updateExpiresInterval);
this.updateExpiresInterval = null;
}
}

_parseAndFormat (id, valueStr) {
/* eslint-disable curly */
if (valueStr === null) valueStr = undefined;
Expand Down
14 changes: 7 additions & 7 deletions saltgui/static/scripts/panels/Stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class StatsPanel extends Panel {

this.onShowNow();

this.updateStatsTimer = window.setInterval(() => {
this.updateStatsInterval = window.setInterval(() => {
this.onShowNow();
}, 5000);
}
Expand All @@ -51,10 +51,10 @@ export class StatsPanel extends Panel {
}

onHide () {
if (this.updateStatsTimer) {
// stop the timer when noone is looking
window.clearInterval(this.updateStatsTimer);
this.updateStatsTimer = null;
if (this.updateStatsInterval) {
// stop the timer when nobody is looking
window.clearInterval(this.updateStatsInterval);
this.updateStatsInterval = null;
}
}

Expand All @@ -70,8 +70,8 @@ export class StatsPanel extends Panel {
_handleStats (pStatsData) {
if (this.showErrorRowInstead(pStatsData)) {
this.statsTd.innerHTML = "<span style='color:red'>this error is typically caused by using the <tt>collect_stats: True</tt> setting in the master configuration file, which is broken in at least the recent versions of salt-api</span>";
window.clearInterval(this.updateStatsTimer);
this.updateStatsTimer = null;
window.clearInterval(this.updateStatsInterval);
this.updateStatsInterval = null;
return;
}

Expand Down

0 comments on commit 2a07c05

Please sign in to comment.