Skip to content

Commit 35e0c72

Browse files
authored
added abort request for when user changes filter and a request is already in progress. added delay to client helpers. (#395)
1 parent b5c385d commit 35e0c72

File tree

3 files changed

+74
-14
lines changed

3 files changed

+74
-14
lines changed

client/containers/workflow-list/component.vue

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ import {
5151
TextInput,
5252
WorkflowGrid,
5353
} from '~components';
54-
import { getEndTimeIsoString, getStartTimeIsoString } from '~helpers';
54+
import { delay, getEndTimeIsoString, getStartTimeIsoString } from '~helpers';
5555
import { httpService } from '~services';
5656
5757
export default {
@@ -76,6 +76,7 @@ export default {
7676
],
7777
data() {
7878
return {
79+
abortController: undefined,
7980
isCronList: IS_CRON_LIST,
8081
loading: false,
8182
results: [],
@@ -207,28 +208,45 @@ export default {
207208
return { workflows, nextPageToken };
208209
}
209210
210-
this.loading = true;
211-
this.error = undefined;
212-
213211
const includeStatus = ![STATUS_ALL, STATUS_OPEN, STATUS_CLOSED].includes(
214212
queryWithStatus.status
215213
);
216214
const { status, ...queryWithoutStatus } = queryWithStatus;
217215
const query = includeStatus ? queryWithStatus : queryWithoutStatus;
218216
219217
try {
220-
const res = await httpService.get(url, { query });
218+
if (this.abortController) {
219+
this.abortController.abort();
220+
await delay();
221+
}
221222
222-
workflows = res.executions;
223+
this.error = undefined;
224+
this.loading = true;
223225
224-
nextPageToken = res.nextPageToken;
225-
} catch (e) {
226-
this.error = (e.json && e.json.message) || e.status || e.message;
227-
}
226+
this.abortController = new AbortController();
227+
const { signal } = this.abortController;
228228
229-
this.loading = false;
229+
const request = await httpService.get(url, { query, signal });
230+
231+
this.abortController = undefined;
232+
233+
workflows = request.executions;
234+
235+
nextPageToken = request.nextPageToken;
236+
} catch (error) {
237+
if (error.name === 'AbortError') {
238+
return { status: 'aborted' };
239+
}
240+
241+
this.error =
242+
(error.json && error.json.message) || error.status || error.message;
230243
231-
return { workflows, nextPageToken };
244+
return { status: 'error' };
245+
} finally {
246+
this.loading = false;
247+
}
248+
249+
return { status: 'success', workflows, nextPageToken };
232250
},
233251
fetchDomain() {
234252
const { domain, now } = this;
@@ -284,33 +302,50 @@ export default {
284302
query.queryString = decodeURI(query.queryString);
285303
}
286304
287-
const { workflows: wfs, nextPageToken } = await this.fetch(
305+
const { status, workflows: wfs, nextPageToken } = await this.fetch(
288306
this.fetchWorkflowListUrl,
289307
query
290308
);
291309
310+
if (status !== 'success') {
311+
return;
312+
}
313+
292314
workflows = wfs;
293315
this.npt = nextPageToken;
294316
} else {
295317
const { domain } = this;
296318
const queryOpen = { ...this.criteria, nextPageToken: this.npt };
297319
const queryClosed = { ...this.criteria, nextPageToken: this.nptAlt };
298320
299-
const { workflows: wfsOpen, nextPageToken: nptOpen } = await this.fetch(
321+
const {
322+
status: openStatus,
323+
workflows: wfsOpen,
324+
nextPageToken: nptOpen,
325+
} = await this.fetch(
300326
`/api/domains/${domain}/workflows/open`,
301327
queryOpen
302328
);
303329
330+
if (openStatus !== 'success') {
331+
return;
332+
}
333+
304334
this.npt = nptOpen;
305335
306336
const {
337+
status: closedStatus,
307338
workflows: wfsClosed,
308339
nextPageToken: nptClosed,
309340
} = await this.fetch(
310341
`/api/domains/${domain}/workflows/closed`,
311342
queryClosed
312343
);
313344
345+
if (closedStatus !== 'success') {
346+
return;
347+
}
348+
314349
this.nptAlt = nptClosed;
315350
316351
workflows = [...wfsOpen, ...wfsClosed];

client/helpers/delay.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) 2021 Uber Technologies Inc.
2+
//
3+
//
4+
// Permission is hereby granted, free of charge, to any person obtaining a copy
5+
// of this software and associated documentation files (the "Software"), to deal
6+
// in the Software without restriction, including without limitation the rights
7+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
// copies of the Software, and to permit persons to whom the Software is
9+
// furnished to do so, subject to the following conditions:
10+
//
11+
// The above copyright notice and this permission notice shall be included in
12+
// all copies or substantial portions of the Software.
13+
//
14+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
// THE SOFTWARE.
21+
22+
const delay = time => new Promise(resolve => setTimeout(resolve, time));
23+
24+
export default delay;

client/helpers/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// THE SOFTWARE.
2121

2222
export { default as combine } from './combine';
23+
export { default as delay } from './delay';
2324
export { default as getDatetimeFormattedString } from './get-datetime-formatted-string';
2425
export { default as getEndTimeIsoString } from './get-end-time-iso-string';
2526
export { default as getEnvironment } from './get-environment';

0 commit comments

Comments
 (0)