From 4e6b06c8d1c965cbae9dd20648480da18ad64b2a Mon Sep 17 00:00:00 2001 From: Ruslan <11838981+feedmeapples@users.noreply.github.com> Date: Mon, 3 May 2021 12:36:14 -0700 Subject: [PATCH] Improve stability of workflows ALL viev (#315) --- client/routes/namespace/workflow-list.vue | 106 ++++++++++------------ server/temporal-client/temporal-client.js | 4 +- 2 files changed, 50 insertions(+), 60 deletions(-) diff --git a/client/routes/namespace/workflow-list.vue b/client/routes/namespace/workflow-list.vue index 24ad780a..f09ba269 100644 --- a/client/routes/namespace/workflow-list.vue +++ b/client/routes/namespace/workflow-list.vue @@ -245,6 +245,8 @@ export default { this.results = []; this.npt = undefined; this.nptAlt = undefined; + this.maxOpen = undefined; + this.maxClosed = undefined; this.fetchWorkflows(); }, typeof Mocha === 'undefined' ? 200 : 60, @@ -312,71 +314,59 @@ export default { this.npt = nextPageToken; }, async fetchWorkflowsAllStates() { - const { namespace } = this; - const queryOpen = { ...this.criteria, nextPageToken: this.npt }; - const queryClosed = { ...this.criteria, nextPageToken: this.nptAlt }; - - // eslint-disable-next-line prefer-const - let { workflows: wfsOpen, nextPageToken: nptOpen } = await this.fetch( - `/api/namespaces/${namespace}/workflows/open`, - queryOpen - ); - - this.npt = nptOpen; - - let { - workflows: wfsClosed, - // eslint-disable-next-line prefer-const - nextPageToken: nptClosed, - } = await this.fetch( - `/api/namespaces/${namespace}/workflows/closed`, - queryClosed - ); - - this.nptAlt = nptClosed; + const { namespace, npt, nptAlt, maxOpen, maxClosed } = this; - if (this.npt && this.nptAlt) { - // saturate diff in workflows between the max dates - // so both open and closed workflows are fetched until the same date - let maxOpen = maxBy(wfsOpen, w => moment(w.startTime)); - let maxClosed = maxBy(wfsClosed, w => moment(w.startTime)); - - let nptDiff; - let saturateOpen; - - if (maxOpen && maxClosed && maxOpen.startTime !== maxClosed.startTime) { - maxOpen = moment(maxOpen.startTime); - maxClosed = moment(maxClosed.startTime); - saturateOpen = maxOpen < maxClosed; + const fetchWorkflowsOpen = async () => { + const query = { ...this.criteria, nextPageToken: npt }; + const { workflows, nextPageToken } = await this.fetch( + `/api/namespaces/${namespace}/workflows/open`, + query + ); - let [startTime, endTime] = saturateOpen - ? [maxOpen, maxClosed] - : [maxClosed, maxOpen]; + this.maxOpen = maxBy(workflows, w => moment(w.startTime)); + this.npt = nextPageToken; + this.results = [...this.results, ...workflows]; + }; - startTime = startTime.add(1, 'seconds').toISOString(); - endTime = endTime.add(1, 'seconds').toISOString(); - const queryDiff = { ...this.criteria, startTime, endTime }; + const fetchWorkflowsClosed = async () => { + const query = { ...this.criteria, nextPageToken: nptAlt }; + const { workflows, nextPageToken } = await this.fetch( + `/api/namespaces/${namespace}/workflows/closed`, + query + ); - const diff = await this.fetch( - `/api/namespaces/${namespace}/workflows/${ - saturateOpen ? 'open' : 'closed' - }`, - queryDiff - ); + this.maxClosed = maxBy(workflows, w => moment(w.startTime)); + this.nptAlt = nextPageToken; + this.results = [...this.results, ...workflows]; + }; - nptDiff = diff.nextPageToken; + if ( + this.results.length === 0 && + npt === undefined && + nptAlt === undefined + ) { + // fetch initial page of both open and closed workflows + await fetchWorkflowsOpen(); + await fetchWorkflowsClosed(); + } else if (!npt && !nptAlt) { + // nothing more to fetch - if (saturateOpen === true) { - this.npt = nptDiff; - wfsOpen = [...wfsOpen, ...diff.workflows]; - } else if (saturateOpen === false) { - this.nptAlt = nptDiff; - wfsClosed = [...wfsClosed, ...diff.workflows]; - } - } + return; + } else if (npt && !nptAlt) { + // only open workflows are left to fetch + await fetchWorkflowsOpen(); + } else if (nptAlt && !npt) { + // only closed workflows are left to fetch + await fetchWorkflowsClosed(); + } else if (maxOpen.startTime > maxClosed.startTime) { + // closed workflows are behind open + // fetch closed workflows + await fetchWorkflowsClosed(); + } else if (maxOpen.startTime <= maxClosed.startTime) { + // open workflows are behind or same date as closed + // fetch open workflows + await fetchWorkflowsOpen(); } - - this.results = [...this.results, ...wfsOpen, ...wfsClosed]; }, setWorkflowFilter(e) { const target = e.target || e.testTarget; // test hook since Event.target is readOnly and unsettable diff --git a/server/temporal-client/temporal-client.js b/server/temporal-client/temporal-client.js index 4fc5949a..5e59f081 100644 --- a/server/temporal-client/temporal-client.js +++ b/server/temporal-client/temporal-client.js @@ -85,7 +85,7 @@ TemporalClient.prototype.openWorkflows = async function( executionFilter, typeFilter, nextPageToken, - maximumPageSize = 100, + maximumPageSize = 10, } ) { const startTimeFilter = { @@ -115,7 +115,7 @@ TemporalClient.prototype.closedWorkflows = async function( typeFilter, status, nextPageToken, - maximumPageSize = 100, + maximumPageSize = 10, } ) { const startTimeFilter = {