| 53 | |
| 54 | actions: { |
| 55 | init({state, commit, dispatch}) { |
| 56 | const store = this; |
| 57 | |
| 58 | axiosInstance.get('executions/active') |
| 59 | .then(({data: activeExecutionIds}) => { |
| 60 | activeExecutionIds.sort((a, b) => parseInt(a) - parseInt(b)); |
| 61 | |
| 62 | const requests = []; |
| 63 | |
| 64 | for (let i = 0; i < activeExecutionIds.length; i++) { |
| 65 | const executionId = activeExecutionIds[i]; |
| 66 | |
| 67 | requests.push(axiosInstance.get('executions/config/' + executionId) |
| 68 | .then((({data: executionConfig}) => { |
| 69 | const executor = scriptExecutor(executionId, executionConfig.scriptName, executionConfig.parameterValues); |
| 70 | |
| 71 | store.registerModule(['executions', executionId], executor); |
| 72 | store.dispatch('executions/' + executionId + '/reconnect'); |
| 73 | |
| 74 | commit('ADD_EXECUTOR', executor); |
| 75 | |
| 76 | return executor; |
| 77 | }))); |
| 78 | } |
| 79 | |
| 80 | if (!isNull(state.currentExecutor)) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | axios.all(requests) |
| 85 | .then(axios.spread((...executors) => { |
| 86 | if (!isNull(state.currentExecutor) || isNull(store.state.scripts.selectedScript)) { |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | const selectedScript = store.state.scripts.selectedScript; |
| 91 | |
| 92 | for (const executor of executors) { |
| 93 | if (selectedScript === executor.state.scriptName) { |
| 94 | dispatch('selectExecutor', executor); |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | })) |
| 99 | .catch(e => console.log(e)); |
| 100 | }) |
| 101 | |
| 102 | }, |
| 103 | |
| 104 | selectScript({state, commit, dispatch}, {selectedScript}) { |
| 105 | let selectedExecutor = null; |