Skip to content
This repository has been archived by the owner on May 26, 2023. It is now read-only.

Commit

Permalink
Improve stability of workflows ALL viev (#315)
Browse files Browse the repository at this point in the history
  • Loading branch information
feedmeapples authored May 3, 2021
1 parent 6ed16d0 commit 4e6b06c
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 60 deletions.
106 changes: 48 additions & 58 deletions client/routes/namespace/workflow-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions server/temporal-client/temporal-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ TemporalClient.prototype.openWorkflows = async function(
executionFilter,
typeFilter,
nextPageToken,
maximumPageSize = 100,
maximumPageSize = 10,
}
) {
const startTimeFilter = {
Expand Down Expand Up @@ -115,7 +115,7 @@ TemporalClient.prototype.closedWorkflows = async function(
typeFilter,
status,
nextPageToken,
maximumPageSize = 100,
maximumPageSize = 10,
}
) {
const startTimeFilter = {
Expand Down

0 comments on commit 4e6b06c

Please sign in to comment.