<commit_before>/* @flow */
var config = require('config');
var dbConfig = config.get('Database');
r = require('rethinkdb');

var connection = null;
if (!connection) {
  r.connect(dbConfig, function(err, conn) {
    if (err) throw err;
    exports.conn = conn;
  });
}
<commit_msg>[FEATURE] auto reconnect to rethinkdb<commit_after>/* @flow */
var config = require('config');
var dbConfig = config.get('Database');
var winston = require('winston');
r = require('rethinkdb');

var connection = null;
exports.connect = function() {
  if (!connection) {
    var interval = setInterval(function() {
      r.connect(dbConfig, function(err, conn) {
        if (err) winston.error('[RethinkDB] ' + err.message);
        exports.conn = conn;
        if (!err && conn) clearInterval(interval);
      });
    }, 5000);
  }
}

exports.connect();

{'fraction_non_alphanumeric': 0.17266187050359713, 'fraction_numerical': 0.004796163069544364, 'mean_word_length': 3.7988505747126435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3691211', 'n_tokens_mistral': 270, 'n_tokens_neox': 264, 'n_words': 66}