<commit_before>/* global API_HOST */
import fetch from 'isomorphic-fetch';

const url = '/api/request';

const START = 'request/START';
const ERROR = 'request/ERROR';
const OK = 'request/OK';
const PROGRESS = 'request/PROGRESS';

export const requestActions = {
  START,
  ERROR,
  OK,
  PROGRESS,
};

const requestStart = () => ({
  type: START,
});

const requestError = error => ({
  type: ERROR,
  error,
});

const requestOk = () => ({
  type: OK,
});

const requestProgress = progress => ({
  type: PROGRESS,
  progress,
});

function poll(dispatch, json, matchId) {
  fetch(`${API_HOST}${url}/${json.job.jobId}`)
    .then(res => res.json())
    .then((json) => {
      if (json.progress) {
        dispatch(requestProgress(json.progress));
      }
      if (json.err || json.state === 'failed') {
        dispatch(requestError(json.err || 'failed'));
      } else if (json.state === 'completed') {
        dispatch(requestOk());
        window.location.href = `/matches/${matchId}`;
      } else {
        setTimeout(poll, 2000, dispatch, { job: json }, matchId);
      }
    });
}

export const postRequest = matchId => (dispatch) => {
  dispatch(requestStart());
  return fetch(`${API_HOST}${url}/${matchId}`, { method: 'post' })
    .then(res => res.json())
    .then((json) => {
      if (json.job && json.job.jobId) {
        poll(dispatch, json, matchId);
      } else {
        dispatch(requestError(json.err));
      }
    })
    .catch(err => dispatch(requestError(err)));
};<commit_msg>request page handle no response<commit_after>/* global API_HOST */
import fetch from 'isomorphic-fetch';

const url = '/api/request';

const START = 'request/START';
const ERROR = 'request/ERROR';
const OK = 'request/OK';
const PROGRESS = 'request/PROGRESS';

export const requestActions = {
  START,
  ERROR,
  OK,
  PROGRESS,
};

const requestStart = () => ({
  type: START,
});

const requestError = error => ({
  type: ERROR,
  error,
});

const requestOk = () => ({
  type: OK,
});

const requestProgress = progress => ({
  type: PROGRESS,
  progress,
});

function poll(dispatch, json, matchId) {
  fetch(`${API_HOST}${url}/${json.job.jobId}`)
    .then(res => res.json())
    .then((json) => {
      if (json && json.progress) {
        dispatch(requestProgress(json.progress));
      }
      if (!json || (json && json.state === 'completed')) {
        dispatch(requestOk());
        window.location.href = `/matches/${matchId}`;
      } else {
        setTimeout(poll, 2000, dispatch, { job: json }, matchId);
      }
    });
}

export const postRequest = matchId => (dispatch) => {
  dispatch(requestStart());
  return fetch(`${API_HOST}${url}/${matchId}`, { method: 'post' })
    .then(res => res.json())
    .then((json) => {
      if (json.job && json.job.jobId) {
        poll(dispatch, json, matchId);
      } else {
        dispatch(requestError(json.err));
      }
    })
    .catch(err => dispatch(requestError(err)));
};
{'fraction_non_alphanumeric': 0.19028202514441048, 'fraction_numerical': 0.0027183146449201497, 'mean_word_length': 3.032876712328767, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5143922', 'n_tokens_mistral': 972, 'n_tokens_neox': 961, 'n_words': 206}