Skip to content

Commit a1f593b

Browse files
authored
Feature/workflow container (part 2) (#277)
* moving workflow into containers * fixing lint * fixing license * changes to the workflow component * more container changes * more container changes * updating containers with workflow container * adding PENDING_TASK_TYPE constants * fixed lint * adding tests for getDefaultState * hooked up initGetters helper method to help initialize getters for unit tests. * finished rest of tests for getters * mutation unit tests * fix lint * fix merge conflict
1 parent bc21015 commit a1f593b

File tree

14 files changed

+736
-53
lines changed

14 files changed

+736
-53
lines changed

client/containers/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@ export {
3636
getters as settingsWorkflowHistoryGetters,
3737
mutations as settingsWorkflowHistoryMutations,
3838
} from './settings-workflow-history';
39-
export { container as Workflow } from './workflow';
39+
export {
40+
container as Workflow,
41+
getDefaultState as getWorkflowDefaultState,
42+
getters as workflowGetters,
43+
mutations as workflowMutations,
44+
} from './workflow';
4045
export {
4146
container as WorkflowHistory,
4247
getDefaultState as getWorkflowHistoryDefaultState,

client/containers/workflow/component.vue

Lines changed: 51 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ export default {
3939
nextPageToken: undefined,
4040
fetchHistoryPageRetryCount: 0,
4141
wfLoading: true,
42-
workflow: undefined,
4342
4443
history: {
4544
loading: undefined,
@@ -63,9 +62,12 @@ export default {
6362
'dateFormat',
6463
'displayWorkflowId',
6564
'domain',
65+
'pendingTaskCount',
6666
'runId',
67+
'taskListName',
6768
'timeFormat',
6869
'timezone',
70+
'workflow',
6971
'workflowHistoryEventHighlightList',
7072
'workflowHistoryEventHighlightListEnabled',
7173
'workflowId',
@@ -74,6 +76,9 @@ export default {
7476
this.unwatch.push(
7577
this.$watch('baseAPIURL', this.onBaseApiUrlChange, { immediate: true })
7678
);
79+
this.unwatch.push(
80+
this.$watch('historyUrl', this.onHistoryUrlChange, { immediate: true })
81+
);
7782
},
7883
beforeDestroy() {
7984
this.clearWatches();
@@ -134,7 +139,6 @@ export default {
134139
this.nextPageToken = undefined;
135140
this.fetchHistoryPageRetryCount = 0;
136141
this.wfLoading = true;
137-
this.workflow = undefined;
138142
139143
this.history.loading = undefined;
140144
@@ -144,17 +148,14 @@ export default {
144148
this.summary.result = undefined;
145149
this.summary.wfStatus = undefined;
146150
this.summary.workflow = undefined;
151+
152+
this.$emit('clearWorkflow');
147153
},
148154
clearWatches() {
149155
while (this.unwatch.length) {
150156
this.unwatch.pop()();
151157
}
152158
},
153-
clearHistoryUrlWatch() {
154-
while (this.unwatch.length > 1) {
155-
this.unwatch.pop()();
156-
}
157-
},
158159
fetchHistoryPage(pagedHistoryUrl) {
159160
if (
160161
!pagedHistoryUrl ||
@@ -240,80 +241,80 @@ export default {
240241
}
241242
});
242243
},
243-
onBaseApiUrlChange(baseAPIURL) {
244+
fetchTaskList() {
245+
const { taskListName } = this;
246+
247+
if (!taskListName) {
248+
return Promise.reject('task list name is required');
249+
}
250+
251+
this.$http(
252+
`/api/domains/${this.$route.params.domain}/task-lists/${taskListName}`
253+
)
254+
.then(
255+
taskList => {
256+
this.taskList = { name: taskListName, ...taskList };
257+
},
258+
error => {
259+
this.taskList = { name: taskListName };
260+
this.error =
261+
(error.json && error.json.message) ||
262+
error.status ||
263+
error.message;
264+
}
265+
)
266+
.finally(() => {
267+
this.loading = false;
268+
});
269+
},
270+
fetchWorkflowInfo() {
271+
const { baseAPIURL } = this;
272+
244273
if (this.baseApiUrlRetryCount >= RETRY_COUNT_MAX) {
245274
return;
246275
}
247276
248-
this.clearHistoryUrlWatch();
249-
this.clearState();
250277
this.wfLoading = true;
251278
252279
return this.$http(baseAPIURL)
253280
.then(
254281
wf => {
255-
this.workflow = wf;
282+
this.$emit('setWorkflow', wf);
256283
this.isWorkflowRunning = !wf.workflowExecutionInfo.closeTime;
257-
this.setupHistoryUrlWatch();
258284
this.baseApiUrlRetryCount = 0;
285+
286+
return wf;
259287
},
260288
error => {
261289
this.$emit('onNotification', {
262290
message: getErrorMessage(error),
263291
type: NOTIFICATION_TYPE_ERROR,
264292
});
265293
this.baseApiUrlRetryCount += 1;
266-
setTimeout(
267-
() => this.onBaseApiUrlChange(baseAPIURL),
268-
RETRY_TIMEOUT
269-
);
294+
setTimeout(() => this.fetchWorkflowInfo(), RETRY_TIMEOUT);
270295
}
271296
)
272297
.finally(() => {
273298
this.wfLoading = false;
274299
});
275300
},
276-
onHistoryUrlChange(historyUrl) {
277-
this.fetchHistoryPage(historyUrl).then(this.fetchTaskList);
301+
onBaseApiUrlChange() {
302+
this.clearState();
303+
},
304+
async onHistoryUrlChange(historyUrl) {
305+
const workflowInfo = await this.fetchWorkflowInfo();
306+
307+
if (workflowInfo) {
308+
await this.fetchHistoryPage(historyUrl);
309+
this.fetchTaskList();
310+
}
278311
},
279312
onNotification(event) {
280313
this.$emit('onNotification', event);
281314
},
282315
onWorkflowHistoryEventParamToggle(event) {
283316
this.$emit('onWorkflowHistoryEventParamToggle', event);
284317
},
285-
setupHistoryUrlWatch() {
286-
this.clearHistoryUrlWatch();
287-
this.unwatch.push(
288-
this.$watch('historyUrl', this.onHistoryUrlChange, { immediate: true })
289-
);
290-
},
291-
fetchTaskList() {
292-
if (!this.workflow || !this.workflow.executionConfiguration) {
293-
return Promise.reject('task list name is required');
294-
}
295-
296-
const taskListName = this.workflow.executionConfiguration.taskList.name;
297-
298-
this.$http(
299-
`/api/domains/${this.$route.params.domain}/task-lists/${taskListName}`
300-
)
301-
.then(
302-
taskList => {
303-
this.taskList = { name: taskListName, ...taskList };
304-
},
305-
error => {
306-
this.taskList = { name: taskListName };
307-
this.error =
308-
(error.json && error.json.message) ||
309-
error.status ||
310-
error.message;
311-
}
312-
)
313-
.finally(() => {
314-
this.loading = false;
315-
});
316-
},
317318
},
318319
};
319320
</script>
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
import { connect } from 'vuex-connect';
23+
import {
24+
WORKFLOW_EXECUTION,
25+
WORKFLOW_EXECUTION_PENDING_TASK_COUNT,
26+
WORKFLOW_EXECUTION_TASK_LIST_NAME,
27+
} from './getter-types';
28+
import {
29+
WORKFLOW_CLEAR_EXECUTION,
30+
WORKFLOW_SET_EXECUTION,
31+
} from './mutation-types';
32+
33+
const gettersToProps = {
34+
pendingTaskCount: WORKFLOW_EXECUTION_PENDING_TASK_COUNT,
35+
taskListName: WORKFLOW_EXECUTION_TASK_LIST_NAME,
36+
workflow: WORKFLOW_EXECUTION,
37+
};
38+
39+
const mutationsToEvents = {
40+
clearWorkflow: WORKFLOW_CLEAR_EXECUTION,
41+
setWorkflow: WORKFLOW_SET_EXECUTION,
42+
};
43+
44+
export default connect({
45+
gettersToProps,
46+
mutationsToEvents,
47+
});

client/containers/workflow/constants.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@
1919
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2020
// THE SOFTWARE.
2121

22+
export const PENDING_TASK_TYPE_ACTIVITY = 'PENDING_TASK_TYPE_ACTIVITY';
23+
export const PENDING_TASK_TYPE_CHILD_WORKFLOW =
24+
'PENDING_TASK_TYPE_CHILD_WORKFLOW';
2225
export const RETRY_COUNT_MAX = 3;
2326
export const RETRY_TIMEOUT = 6000;
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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 getDefaultState = (state = {}) => ({
23+
execution: null,
24+
isLoading: true,
25+
...state,
26+
});
27+
28+
export default getDefaultState;
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
import getDefaultState from './get-default-state';
23+
24+
describe('workflow getDefaultState', () => {
25+
describe('when state is not passed', () => {
26+
it('should return execution = null.', () => {
27+
const output = getDefaultState();
28+
29+
expect(output.execution).toEqual(null);
30+
});
31+
32+
it('should return isLoading = true.', () => {
33+
const output = getDefaultState();
34+
35+
expect(output.isLoading).toEqual(true);
36+
});
37+
});
38+
39+
describe('when state is passed with execution defined', () => {
40+
const state = { execution: {} };
41+
42+
it('should return execution.', () => {
43+
const output = getDefaultState(state);
44+
45+
expect(output.execution).toEqual({});
46+
});
47+
});
48+
49+
describe('when state is passed with isLoading = false', () => {
50+
const state = { isLoading: false };
51+
52+
it('should return isLoading = false.', () => {
53+
const output = getDefaultState(state);
54+
55+
expect(output.isLoading).toEqual(false);
56+
});
57+
});
58+
});
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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+
export const WORKFLOW_EXECUTION = 'WORKFLOW_EXECUTION';
23+
export const WORKFLOW_EXECUTION_IS_LOADING = 'WORKFLOW_EXECUTION_IS_LOADING';
24+
export const WORKFLOW_EXECUTION_PENDING_ACTIVITIES =
25+
'WORKFLOW_EXECUTION_PENDING_ACTIVITIES';
26+
export const WORKFLOW_EXECUTION_PENDING_CHILDREN =
27+
'WORKFLOW_EXECUTION_PENDING_CHILDREN';
28+
export const WORKFLOW_EXECUTION_PENDING_TASK_COUNT =
29+
'WORKFLOW_EXECUTION_PENDING_TASK_COUNT';
30+
export const WORKFLOW_EXECUTION_PENDING_TASKS =
31+
'WORKFLOW_EXECUTION_PENDING_TASKS';
32+
export const WORKFLOW_EXECUTION_TASK_LIST_NAME =
33+
'WORKFLOW_EXECUTION_TASK_LIST_NAME';

0 commit comments

Comments
 (0)