Sha256: 9ea7a81a2c9d592a4100250e8c137bc80f03d6d4d87cdcd5db42967266afdc32
Contents?: true
Size: 1.98 KB
Versions: 50
Compression:
Stored size: 1.98 KB
Contents
// eslint-disable-next-line import/no-extraneous-dependencies import API from 'foremanReact/API'; import { JOB_INVOCATIONS_GET_JOB_INVOCATIONS, JOB_INVOCATIONS_POLLING_STARTED, JOB_INVOCATIONS_JOB_FINISHED, } from '../../consts'; const defaultJobInvocationsPollingInterval = 1000; const jobInvocationsInterval = process.env.JOB_INVOCATIONS_POLLING || defaultJobInvocationsPollingInterval; const getJobInvocations = url => async (dispatch, getState) => { function onGetJobInvocationsSuccess({ data }) { // If the job has finished, stop polling if (data.finished) { dispatch({ type: JOB_INVOCATIONS_JOB_FINISHED, payload: { jobInvocations: data, }, }); } else { dispatch({ type: JOB_INVOCATIONS_GET_JOB_INVOCATIONS, payload: { jobInvocations: data, }, }); } } function onGetJobInvocationsFailed(error) { if (error.response.status === 401) { window.location.replace('/users/login'); } } function triggerPolling() { if (jobInvocationsInterval) { setTimeout( () => dispatch(getJobInvocations(url)), jobInvocationsInterval ); } } const isDocumentVisible = document.visibilityState === 'visible' || document.visibilityState === 'prerender'; if (getState().foremanRemoteExecutionReducers.jobInvocations.isPolling) { if (isDocumentVisible) { try { const data = await API.get(url); onGetJobInvocationsSuccess(data); } catch (error) { onGetJobInvocationsFailed(error); } finally { triggerPolling(); } } else { // document is not visible, keep polling without api call triggerPolling(); } } }; export const startJobInvocationsPolling = url => (dispatch, getState) => { if (getState().foremanRemoteExecutionReducers.jobInvocations.isPolling) { return; } dispatch({ type: JOB_INVOCATIONS_POLLING_STARTED, }); dispatch(getJobInvocations(url)); };
Version data entries
50 entries across 50 versions & 1 rubygems