Welcome to mirror list, hosted at ThFree Co, Russian Federation.

session_status.js « actions « terminal « modules « stores « ide « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d715d555aa90a87d08e8d0646c783aaf19d232dc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import axios from '~/lib/utils/axios_utils';
import { deprecatedCreateFlash as flash } from '~/flash';
import * as types from '../mutation_types';
import * as messages from '../messages';
import { isEndingStatus } from '../utils';

export const pollSessionStatus = ({ state, dispatch, commit }) => {
  dispatch('stopPollingSessionStatus');
  dispatch('fetchSessionStatus');

  const interval = setInterval(() => {
    if (!state.session) {
      dispatch('stopPollingSessionStatus');
    } else {
      dispatch('fetchSessionStatus');
    }
  }, 5000);

  commit(types.SET_SESSION_STATUS_INTERVAL, interval);
};

export const stopPollingSessionStatus = ({ state, commit }) => {
  const { sessionStatusInterval } = state;

  if (!sessionStatusInterval) {
    return;
  }

  clearInterval(sessionStatusInterval);

  commit(types.SET_SESSION_STATUS_INTERVAL, 0);
};

export const receiveSessionStatusSuccess = ({ commit, dispatch }, data) => {
  const status = data && data.status;

  commit(types.SET_SESSION_STATUS, status);

  if (isEndingStatus(status)) {
    dispatch('killSession');
  }
};

export const receiveSessionStatusError = ({ dispatch }) => {
  flash(messages.UNEXPECTED_ERROR_STATUS);
  dispatch('killSession');
};

export const fetchSessionStatus = ({ dispatch, state }) => {
  if (!state.session) {
    return;
  }

  const { showPath } = state.session;

  axios
    .get(showPath)
    .then(({ data }) => {
      dispatch('receiveSessionStatusSuccess', data);
    })
    .catch(error => {
      dispatch('receiveSessionStatusError', error);
    });
};