Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/workflow container (part 2) #277

Merged
merged 19 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = {
"~containers": "./client/containers",
"~helpers": "./client/helpers",
"~services": "./client/services",
"~test": "./test/helpers",
just-at-uber marked this conversation as resolved.
Show resolved Hide resolved
},
}
],
Expand Down
6 changes: 6 additions & 0 deletions client/containers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export {
mutations as settingsWorkflowHistoryMutations,
} from './settings-workflow-history';
export { container as Workflow } from './workflow';
export {
container as Workflow,
getDefaultState as getWorkflowDefaultState,
getters as workflowGetters,
mutations as workflowMutations,
} from './workflow';
export {
container as WorkflowHistory,
getDefaultState as getWorkflowHistoryDefaultState,
Expand Down
101 changes: 51 additions & 50 deletions client/containers/workflow/component.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ export default {
nextPageToken: undefined,
fetchHistoryPageRetryCount: 0,
wfLoading: true,
workflow: undefined,

history: {
loading: undefined,
Expand All @@ -63,9 +62,12 @@ export default {
'dateFormat',
'displayWorkflowId',
'domain',
'pendingTaskCount',
'runId',
'taskListName',
'timeFormat',
'timezone',
'workflow',
'workflowHistoryEventHighlightList',
'workflowHistoryEventHighlightListEnabled',
'workflowId',
Expand All @@ -74,6 +76,9 @@ export default {
this.unwatch.push(
this.$watch('baseAPIURL', this.onBaseApiUrlChange, { immediate: true })
);
this.unwatch.push(
this.$watch('historyUrl', this.onHistoryUrlChange, { immediate: true })
);
},
beforeDestroy() {
this.clearWatches();
Expand Down Expand Up @@ -134,7 +139,6 @@ export default {
this.nextPageToken = undefined;
this.fetchHistoryPageRetryCount = 0;
this.wfLoading = true;
this.workflow = undefined;

this.history.loading = undefined;

Expand All @@ -144,17 +148,14 @@ export default {
this.summary.result = undefined;
this.summary.wfStatus = undefined;
this.summary.workflow = undefined;

this.$emit('clearWorkflow');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workflow execution stored in vuex

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it clean the wf state?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct. It will clear all data for the workflow in the vuex store.

},
clearWatches() {
while (this.unwatch.length) {
this.unwatch.pop()();
}
},
clearHistoryUrlWatch() {
while (this.unwatch.length > 1) {
this.unwatch.pop()();
}
},
fetchHistoryPage(pagedHistoryUrl) {
if (
!pagedHistoryUrl ||
Expand Down Expand Up @@ -240,80 +241,80 @@ export default {
}
});
},
onBaseApiUrlChange(baseAPIURL) {
fetchTaskList() {
Copy link
Contributor Author

@just-at-uber just-at-uber Apr 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

code moved into alphabetical order. No changes in function except taskListName coming from props instead of referencing from the workflow.

const { taskListName } = this;

if (!taskListName) {
return Promise.reject('task list name is required');
}

this.$http(
`/api/domains/${this.$route.params.domain}/task-lists/${taskListName}`
)
.then(
taskList => {
this.taskList = { name: taskListName, ...taskList };
},
error => {
this.taskList = { name: taskListName };
this.error =
(error.json && error.json.message) ||
error.status ||
error.message;
}
)
.finally(() => {
this.loading = false;
});
},
fetchWorkflowInfo() {
const { baseAPIURL } = this;

if (this.baseApiUrlRetryCount >= RETRY_COUNT_MAX) {
return;
}

this.clearHistoryUrlWatch();
this.clearState();
this.wfLoading = true;

return this.$http(baseAPIURL)
.then(
wf => {
this.workflow = wf;
this.$emit('setWorkflow', wf);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workflow execution stored in vuex

this.isWorkflowRunning = !wf.workflowExecutionInfo.closeTime;
this.setupHistoryUrlWatch();
this.baseApiUrlRetryCount = 0;

return wf;
},
error => {
this.$emit('onNotification', {
message: getErrorMessage(error),
type: NOTIFICATION_TYPE_ERROR,
});
this.baseApiUrlRetryCount += 1;
setTimeout(
() => this.onBaseApiUrlChange(baseAPIURL),
RETRY_TIMEOUT
);
setTimeout(() => this.fetchWorkflowInfo(), RETRY_TIMEOUT);
}
)
.finally(() => {
this.wfLoading = false;
});
},
onHistoryUrlChange(historyUrl) {
this.fetchHistoryPage(historyUrl).then(this.fetchTaskList);
onBaseApiUrlChange() {
this.clearState();
},
async onHistoryUrlChange(historyUrl) {
const workflowInfo = await this.fetchWorkflowInfo();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

workflow execution now polled while workflow is running

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

historyUrl will change when received new page token for history API.


if (workflowInfo) {
await this.fetchHistoryPage(historyUrl);
this.fetchTaskList();
}
},
onNotification(event) {
this.$emit('onNotification', event);
},
onWorkflowHistoryEventParamToggle(event) {
this.$emit('onWorkflowHistoryEventParamToggle', event);
},
setupHistoryUrlWatch() {
this.clearHistoryUrlWatch();
this.unwatch.push(
this.$watch('historyUrl', this.onHistoryUrlChange, { immediate: true })
);
},
fetchTaskList() {
if (!this.workflow || !this.workflow.executionConfiguration) {
return Promise.reject('task list name is required');
}

const taskListName = this.workflow.executionConfiguration.taskList.name;

this.$http(
`/api/domains/${this.$route.params.domain}/task-lists/${taskListName}`
)
.then(
taskList => {
this.taskList = { name: taskListName, ...taskList };
},
error => {
this.taskList = { name: taskListName };
this.error =
(error.json && error.json.message) ||
error.status ||
error.message;
}
)
.finally(() => {
this.loading = false;
});
},
},
};
</script>
Expand Down
47 changes: 47 additions & 0 deletions client/containers/workflow/connector.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright (c) 2021 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import { connect } from 'vuex-connect';
import {
WORKFLOW_EXECUTION,
WORKFLOW_EXECUTION_PENDING_TASK_COUNT,
WORKFLOW_EXECUTION_TASK_LIST_NAME,
} from './getter-types';
import {
WORKFLOW_CLEAR_EXECUTION,
WORKFLOW_SET_EXECUTION,
} from './mutation-types';

const gettersToProps = {
pendingTaskCount: WORKFLOW_EXECUTION_PENDING_TASK_COUNT,
taskListName: WORKFLOW_EXECUTION_TASK_LIST_NAME,
workflow: WORKFLOW_EXECUTION,
};

const mutationsToEvents = {
clearWorkflow: WORKFLOW_CLEAR_EXECUTION,
setWorkflow: WORKFLOW_SET_EXECUTION,
};

export default connect({
gettersToProps,
mutationsToEvents,
});
3 changes: 3 additions & 0 deletions client/containers/workflow/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,8 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export const PENDING_TASK_TYPE_ACTIVITY = 'PENDING_TASK_TYPE_ACTIVITY';
export const PENDING_TASK_TYPE_CHILD_WORKFLOW =
'PENDING_TASK_TYPE_CHILD_WORKFLOW';
export const RETRY_COUNT_MAX = 3;
export const RETRY_TIMEOUT = 6000;
28 changes: 28 additions & 0 deletions client/containers/workflow/get-default-state.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright (c) 2021 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

const getDefaultState = (state = {}) => ({
execution: null,
isLoading: true,
...state,
});

export default getDefaultState;
58 changes: 58 additions & 0 deletions client/containers/workflow/get-default-state.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright (c) 2021 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

import getDefaultState from './get-default-state';

describe('workflow getDefaultState', () => {
describe('when state is not passed', () => {
it('should return execution = null.', () => {
const output = getDefaultState();

expect(output.execution).toEqual(null);
});

it('should return isLoading = true.', () => {
const output = getDefaultState();

expect(output.isLoading).toEqual(true);
});
});

describe('when state is passed with execution defined', () => {
const state = { execution: {} };

it('should return execution.', () => {
const output = getDefaultState(state);

expect(output.execution).toEqual({});
});
});

describe('when state is passed with isLoading = false', () => {
const state = { isLoading: false };

it('should return isLoading = false.', () => {
const output = getDefaultState(state);

expect(output.isLoading).toEqual(false);
});
});
});
33 changes: 33 additions & 0 deletions client/containers/workflow/getter-types.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2021 Uber Technologies Inc.
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

export const WORKFLOW_EXECUTION = 'WORKFLOW_EXECUTION';
export const WORKFLOW_EXECUTION_IS_LOADING = 'WORKFLOW_EXECUTION_IS_LOADING';
export const WORKFLOW_EXECUTION_PENDING_ACTIVITIES =
'WORKFLOW_EXECUTION_PENDING_ACTIVITIES';
export const WORKFLOW_EXECUTION_PENDING_CHILDREN =
'WORKFLOW_EXECUTION_PENDING_CHILDREN';
export const WORKFLOW_EXECUTION_PENDING_TASK_COUNT =
'WORKFLOW_EXECUTION_PENDING_TASK_COUNT';
export const WORKFLOW_EXECUTION_PENDING_TASKS =

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we may want to have one for pending decision as well in the future, if possible, like we already do for the CLI

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good. I couldn't see it being returned in the current API but it is the plan once this is returned.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Screen Shot 2021-04-19 at 10 24 52 AM

'WORKFLOW_EXECUTION_PENDING_TASKS';
export const WORKFLOW_EXECUTION_TASK_LIST_NAME =
'WORKFLOW_EXECUTION_TASK_LIST_NAME';
Loading