<commit_before>import React, { Component, PropTypes } from 'react';
import {connect} from 'react-redux';
import Messenger from 'messenger';
import Navigation from './Navigation';
import GlobalSearch from '../globalSearch/GlobalSearch';
import Title from './Title';
import Utils from '../../utils';

class Application extends Component {
  constructor(props) {
    super(props);
    this.state = {
      lagErrorDismissed: false,
    };
    this.dismissLagError = this.dismissLagError.bind(this);
    this.notifyLag = this.notifyLag.bind(this);
  }

  dismissLagError() {
    this.setState({ lagErrorDismissed: true });
  }

  notifyLag(maxTaskLag) {
    const { lagErrorDismissed } = this.state;
    const taskLagMinutes = maxTaskLag / 1000 / 60;
    if (!lagErrorDismissed && taskLagMinutes >= 0) {
      Messenger().error({
        onClickClose: this.dismissLagError,
        message: `
          Singularity is experiencing some delays. The team has already been
          notified. (Max task lag: ${Utils.duration(maxTaskLag)})
        `,
      });
    }
  }

  render() {
    this.notifyLag(this.props.maxTaskLag);

    return (
      <div>
        <Title routes={this.props.routes} params={this.props.params} />
        <Navigation location={this.props.location} history={this.props.history} />
        <GlobalSearch />
        {this.props.children}
      </div>
    );
  }
}

Application.propTypes = {
  children: PropTypes.object,
  history: PropTypes.object.isRequired,
  location: PropTypes.object.isRequired,
  maxTaskLag: PropTypes.number,
  params: PropTypes.object.isRequired,
  routes: PropTypes.arrayOf(PropTypes.object).isRequired,
};<commit_msg>Add dismissal timer for lag notification<commit_after>import React, { Component, PropTypes } from 'react';
import {connect} from 'react-redux';
import Messenger from 'messenger';
import Navigation from './Navigation';
import GlobalSearch from '../globalSearch/GlobalSearch';
import Title from './Title';
import Utils from '../../utils';

const PAUSE_INTERVAL_IN_MS = 1000 * 60 * 60;
const LAG_THRESHOLD_IN_MS = 1000 * 60 * 3;

class Application extends Component {
  constructor(props) {
    super(props);
    this.state = {
      canShowLagError: true,
    };
    _.bindAll(this,
      'pauseNotification',
      'notifyLag',
    );
  }

  componentWillUnmount() {
    clearInterval(this.timerId);
  }

  pauseNotification() {
    this.setState({ canShowLagError: false });
    this.timerId = setInterval(() => {
      clearInterval(this.timerId);
      this.setState({ canShowLagError: true });
    }, PAUSE_INTERVAL_IN_MS);
  }

  notifyLag(maxTaskLag) {
    const { canShowLagError: canNotify } = this.state;
    const shouldNotify = maxTaskLag >= LAG_THRESHOLD_IN_MS;
    if (canNotify && shouldNotify) {
      Messenger().error({
        onClickClose: this.pauseNotification,
        message: `
          Singularity is experiencing some delays. The team has already been
          notified. (Max task lag: ${Utils.duration(maxTaskLag)})
        `,
      });
    }
  }

  render() {
    this.notifyLag(this.props.maxTaskLag);

    return (
      <div>
        <Title routes={this.props.routes} params={this.props.params} />
        <Navigation location={this.props.location} history={this.props.history} />
        <GlobalSearch />
        {this.props.children}
      </div>
    );
  }
}

Application.propTypes = {
  children: PropTypes.object,
  history: PropTypes.object.isRequired,
  location: PropTypes.object.isRequired,
  maxTaskLag: PropTypes.number,
  params: PropTypes.object.isRequired,
  routes: PropTypes.arrayOf(PropTypes.object).isRequired,
};
{'fraction_non_alphanumeric': 0.12796469939327082, 'fraction_numerical': 0.006067291781577496, 'mean_word_length': 3.2076566125290022, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 16, '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': '2268997', 'n_tokens_mistral': 1134, 'n_tokens_neox': 1084, 'n_words': 232}