<commit_before>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { injectIntl, defineMessages, FormattedMessage } from 'react-intl';
import { ProgressBar, Intent, Button, Tooltip } from '@blueprintjs/core';

import { Numeric } from 'src/components/common';
import { triggerCollectionCancel, fetchCollectionStatus } from 'src/actions';
import { selectCollectionStatus } from 'src/selectors';
// import wordList from 'src/util/wordList';

import './CollectionStatus.scss';

const messages = defineMessages({
  cancel_button: {
    id: 'collection.status.cancel_button',
    defaultMessage: 'Cancel the process',
  },
});


class CollectionStatus extends Component {
  constructor(props) {
    super(props);
    this.fetchStatus = this.fetchStatus.bind(this);
    this.onCancel = this.onCancel.bind(this);
  }

  componentDidMount() {
    this.fetchStatus();
  }

  componentWillUnmount() {
    clearTimeout(this.timeout);
  }

  onCancel() {
    const { collection } = this.props;
    this.props.triggerCollectionCancel(collection.id);
  }

  fetchStatus() {
    const { collection, status } = this.props;
    this.props.fetchCollectionStatus(collection);
    const duration = status.pending === 0 ? 6000 : 2000;
    this.timeout = setTimeout(this.fetchStatus, duration);
  }

  render() {
    const { collection, status, intl } = this.props;
    const pending = status.pending || 0;
    const finished = status.finished || 0;
    const total = pending + finished;
    if (!collection || status.shouldLoad || !pending) {
      return null;
    }
    const determinate = pending > 6;<commit_msg>fetch collection status: call next fetch after the previous one finished to avoid a pile of unfinished requests in case the server is unable to respond in 2 or 6 seconds<commit_after>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { injectIntl, defineMessages, FormattedMessage } from 'react-intl';
import { ProgressBar, Intent, Button, Tooltip } from '@blueprintjs/core';

import { Numeric } from 'src/components/common';
import { triggerCollectionCancel, fetchCollectionStatus } from 'src/actions';
import { selectCollectionStatus } from 'src/selectors';
// import wordList from 'src/util/wordList';

import './CollectionStatus.scss';

const messages = defineMessages({
  cancel_button: {
    id: 'collection.status.cancel_button',
    defaultMessage: 'Cancel the process',
  },
});


class CollectionStatus extends Component {
  constructor(props) {
    super(props);
    this.fetchStatus = this.fetchStatus.bind(this);
    this.onCancel = this.onCancel.bind(this);
  }

  componentDidMount() {
    this.fetchStatus();
  }

  componentWillUnmount() {
    clearTimeout(this.timeout);
  }

  onCancel() {
    const { collection } = this.props;
    this.props.triggerCollectionCancel(collection.id);
  }

  fetchStatus() {
    const { collection } = this.props;
    this.props.fetchCollectionStatus(collection)
      .finally(() => {
        const { status } = this.props;
        const duration = status.pending === 0 ? 6000 : 2000;
        this.timeout = setTimeout(this.fetchStatus, duration);
      });
  }

  render() {
    const { collection, status, intl } = this.props;
    const pending = status.pending || 0;
    const finished = status.finished || 0;
    const total = pending + finished;
    if (!collection || status.shouldLoad || !pending) {
      return null;
    }
    const determinate = pending > 6;
{'fraction_non_alphanumeric': 0.12274161170060224, 'fraction_numerical': 0.007456266131344996, 'mean_word_length': 3.7650273224043715, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5038259', 'n_tokens_mistral': 1013, 'n_tokens_neox': 976, 'n_words': 258}