<commit_before>'use strict';

var pg = require('pg');

var conString = 'postgres://' +
                process.env.POSTGRES_USER +
                ':' +
                process.env.POSTGRES_PASSWORD +
                '@' +
                process.env.POSTGRES_HOST +
                ':' +
                process.env.POSTGRES_PORT +
                '/postgres';

console.log('conString', conString);

var MAX_ATTEMPTS = 10;
var INITIAL_TIMEOUT_TIME = 100;

module.exports = function(){
    var attempts = 0;
    
    return new Promise(function(resolve, reject){
        
        (function tryConnect(time){
            setTimeout(function(){
                
                var client = new pg.Client(conString);

                client.connect(function(err) {
                    if(err){
                        if(attempts >= MAX_ATTEMPTS)
                            reject(err); 
                        else
                            // wait twice more to give time and not overwhelm the database with useless attempts to connect
                            tryConnect(2*time); 
                    }
                    else{
                        resolve(client);
                    }
                
                    attempts++;
                });

            }, time);
        })(INITIAL_TIMEOUT_TIME);
        
    });
};
<commit_msg>forgot a DB connection<commit_after>'use strict';

var pg = require('pg');

var conString = 'postgres://' +
                process.env.POSTGRES_USER +
                ':' +
                process.env.POSTGRES_PASSWORD +
                '@' +
                process.env.DB_PORT_5432_TCP_ADDR +
                ':' +
                process.env.DB_PORT_5432_TCP_PORT +
                '/postgres';

console.log('conString', conString);

var MAX_ATTEMPTS = 10;
var INITIAL_TIMEOUT_TIME = 100;

module.exports = function(){
    var attempts = 0;
    
    return new Promise(function(resolve, reject){
        
        (function tryConnect(time){
            setTimeout(function(){
                
                var client = new pg.Client(conString);

                client.connect(function(err) {
                    if(err){
                        if(attempts >= MAX_ATTEMPTS)
                            reject(err); 
                        else
                            // wait twice more to give time and not overwhelm the database with useless attempts to connect
                            tryConnect(2*time); 
                    }
                    else{
                        resolve(client);
                    }
                
                    attempts++;
                });

            }, time);
        })(INITIAL_TIMEOUT_TIME);
        
    });
};

{'fraction_non_alphanumeric': 0.09485589201021526, 'fraction_numerical': 0.008026267785479753, 'mean_word_length': 1.0741301059001513, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '5430374', 'n_tokens_mistral': 715, 'n_tokens_neox': 654, 'n_words': 133}