diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 14:59:07 +0300 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /app/assets/javascripts/jobs/store/actions.js | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'app/assets/javascripts/jobs/store/actions.js')
-rw-r--r-- | app/assets/javascripts/jobs/store/actions.js | 35 |
1 files changed, 30 insertions, 5 deletions
diff --git a/app/assets/javascripts/jobs/store/actions.js b/app/assets/javascripts/jobs/store/actions.js index 1e4b5e986db..cac9dc06284 100644 --- a/app/assets/javascripts/jobs/store/actions.js +++ b/app/assets/javascripts/jobs/store/actions.js @@ -13,6 +13,7 @@ import { scrollDown, scrollUp, } from '~/lib/utils/scroll_utils'; +import httpStatusCodes from '~/lib/utils/http_status'; export const init = ({ dispatch }, { endpoint, logState, pagePath }) => { dispatch('setJobEndpoint', endpoint); @@ -20,8 +21,7 @@ export const init = ({ dispatch }, { endpoint, logState, pagePath }) => { logState, pagePath, }); - - return Promise.all([dispatch('fetchJob'), dispatch('fetchTrace')]); + dispatch('fetchJob'); }; export const setJobEndpoint = ({ commit }, endpoint) => commit(types.SET_JOB_ENDPOINT, endpoint); @@ -39,6 +39,7 @@ export const toggleSidebar = ({ dispatch, state }) => { }; let eTagPoll; +let isTraceReadyForRender; export const clearEtagPoll = () => { eTagPoll = null; @@ -70,7 +71,14 @@ export const fetchJob = ({ state, dispatch }) => { }); if (!Visibility.hidden()) { - eTagPoll.makeRequest(); + // eslint-disable-next-line promise/catch-or-return + eTagPoll.makeRequest().then(() => { + // if a job is canceled we still need to dispatch + // fetchTrace to get the trace so we check for has_trace + if (state.job.started || state.job.has_trace) { + dispatch('fetchTrace'); + } + }); } else { axios .get(state.jobEndpoint) @@ -80,9 +88,15 @@ export const fetchJob = ({ state, dispatch }) => { Visibility.change(() => { if (!Visibility.hidden()) { + // This check is needed to ensure the loading icon + // is not shown for a finished job during a visibility change + if (!isTraceReadyForRender && state.job.started) { + dispatch('startPollingTrace'); + } dispatch('restartPolling'); } else { dispatch('stopPolling'); + dispatch('stopPollingTrace'); } }); }; @@ -163,6 +177,8 @@ export const fetchTrace = ({ dispatch, state }) => params: { state: state.traceState }, }) .then(({ data }) => { + isTraceReadyForRender = data.complete; + dispatch('toggleScrollisInBottom', isScrolledToBottom()); dispatch('receiveTraceSuccess', data); @@ -172,7 +188,11 @@ export const fetchTrace = ({ dispatch, state }) => dispatch('startPollingTrace'); } }) - .catch(() => dispatch('receiveTraceError')); + .catch(e => + e.response.status === httpStatusCodes.FORBIDDEN + ? dispatch('receiveTraceUnauthorizedError') + : dispatch('receiveTraceError'), + ); export const startPollingTrace = ({ dispatch, commit }) => { const traceTimeout = setTimeout(() => { @@ -194,6 +214,10 @@ export const receiveTraceError = ({ dispatch }) => { dispatch('stopPollingTrace'); flash(__('An error occurred while fetching the job log.')); }; +export const receiveTraceUnauthorizedError = ({ dispatch }) => { + dispatch('stopPollingTrace'); + flash(__('The current user is not authorized to access the job log.')); +}; /** * When the user clicks a collapsible line in the job * log, we commit a mutation to update the state @@ -234,7 +258,7 @@ export const receiveJobsForStageError = ({ commit }) => { flash(__('An error occurred while fetching the jobs.')); }; -export const triggerManualJob = ({ state }, variables) => { +export const triggerManualJob = ({ state, dispatch }, variables) => { const parsedVariables = variables.map(variable => { const copyVar = { ...variable }; delete copyVar.id; @@ -245,5 +269,6 @@ export const triggerManualJob = ({ state }, variables) => { .post(state.job.status.action.path, { job_variables_attributes: parsedVariables, }) + .then(() => dispatch('fetchTrace')) .catch(() => flash(__('An error occurred while triggering the job.'))); }; |