<commit_before>var _ = require('lodash');
var async = require('async');
var json = require('../../util/json');
var logger = require('../../util/logger');

module.exports = getRepoCopJson;

function getRepoCopJson(organisation, next) {

    var q = async.queue(function(task, callback) {
        logger.info("Fetching %s metadata", task.repo.full_name);

        organisation.provider.getBytes(task.organisation.name, task.repo.name, 'repocop.json', function(err, buffer) {  
            if (err) return captureError(task.repo, err, callback);
            if (!buffer) return callback();
            parseRepoCopJson(task.repo, buffer, callback);
        });
    }, 5);

    q.drain = next;

    _.each(organisation.repositories, function(repo) {
        q.push({organisation: organisation, repo: repo})
    })

    function parseRepoCopJson(repo, buffer, next) {
        json.parse(buffer.toString('utf8'), function(err, repocopJson) {
            if (err) return captureError(repo, err, next);
            repo.metadata = repocopJson;
            next();                
        });
    }

    function captureError(repo, err, next) {
        repo.error = err;
        logger.error('Error fetching metadata for %s : %s', repo.name, err.message);
        next();
    }
}<commit_msg>Reducing number of queue workers to reduce load on github<commit_after>var _ = require('lodash');
var async = require('async');
var json = require('../../util/json');
var logger = require('../../util/logger');

module.exports = getRepoCopJson;

function getRepoCopJson(organisation, next) {

    var q = async.queue(function(task, callback) {
        logger.info("Fetching %s metadata", task.repo.full_name);

        organisation.provider.getBytes(task.organisation.name, task.repo.name, 'repocop.json', function(err, buffer) {  
            if (err) return captureError(task.repo, err, callback);
            if (!buffer) return callback();
            parseRepoCopJson(task.repo, buffer, callback);
        });
    }, 2);

    q.drain = next;

    _.each(organisation.repositories, function(repo) {
        q.push({organisation: organisation, repo: repo})
    })

    function parseRepoCopJson(repo, buffer, next) {
        json.parse(buffer.toString('utf8'), function(err, repocopJson) {
            if (err) return captureError(repo, err, next);
            repo.metadata = repocopJson;
            next();                
        });
    }

    function captureError(repo, err, next) {
        repo.error = err;
        logger.error('Error fetching metadata for %s : %s', repo.name, err.message);
        next();
    }
}
{'fraction_non_alphanumeric': 0.14493865030674846, 'fraction_numerical': 0.0015337423312883436, 'mean_word_length': 2.664325842696629, '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': '108524', 'n_tokens_mistral': 767, 'n_tokens_neox': 757, 'n_words': 173}