<commit_before>var S            = require('string');
var async        = require('async');
var request      = require('request');
var ovh          = require('./ovhApi');
var mailer       = require('./mailer');
var pushbullet   = require('./pushbulletApi.js');
var newrelic     = require('./newrelicApi.js');
var requestModel = require('../models/requests');

/*
 *  Traitement de l'ensemble des demandes en attente
 *  Route : /cron/handleRequests/:secureKey
 *  Methode : GET
 */
exports.handleRequests = function( req, res, next ) {

    checkSecureKey(req, res, req.params.secureKey, function() {
    requestModel.getPendingRequests(next, function( pendingRequests ) {
    ovh.getJson(next, function( json ) {

        var availableOffers = [];

        async.each(pendingRequests, function( request, nextRequest ) {
            ovh.checkOffer(json, request.reference, request.zone, next, function( available ) {

                if( available ) {

                    var offer = {
                        hash:hash( request.name + request.zone ),
                        offer:request.name,
                        zone:( request.zone == 'all' ) ? 'europe' : request.zone,
                    };

                    availableOffers.push( offer );
                    inform( res, request, next );

                }

                nextRequest();

            });

        }, function( err ) {

            var arr = {};

            for( var i = 0; i < availableOffers.length; i++ )
                arr[availableOffers[i].hash] = availableOffers[i];

            availableOffers = [];

            for( var key in arr )
                availableOffers.push( arr[key] );

            var events = [];

            async.each(availableOffers, function( availableOffer, nextOffer ) {

                var eventObject = {
                    "eventType":"availableOffers",<commit_msg>Correction d'un bug de duplication<commit_after>var S            = require('string');
var async        = require('async');
var request      = require('request');
var ovh          = require('./ovhApi');
var mailer       = require('./mailer');
var pushbullet   = require('./pushbulletApi.js');
var newrelic     = require('./newrelicApi.js');
var requestModel = require('../models/requests');

/*
 *  Traitement de l'ensemble des demandes en attente
 *  Route : /cron/handleRequests/:secureKey
 *  Methode : GET
 */
exports.handleRequests = function( req, res, next ) {

    checkSecureKey(req, res, req.params.secureKey, function() {
    requestModel.getPendingRequests(next, function( pendingRequests ) {
    ovh.getJson(next, function( json ) {

        var availableOffers = [];

        async.each(pendingRequests, function( request, nextRequest ) {
            ovh.checkOffer(json, request.reference, request.zone, next, function( available ) {

                if( available ) {

                    var zone  = ( request.zone == 'all' ) ? 'europe' : request.zone;
                    var offer = {
                        hash:hash( request.name + zone ),
                        offer:request.name,
                        zone:zone
                    };

                    availableOffers.push( offer );
                    inform( res, request, next );

                }

                nextRequest();

            });

        }, function( err ) {

            var arr = {};

            for( var i = 0; i < availableOffers.length; i++ )
                arr[availableOffers[i].hash] = availableOffers[i];

            availableOffers = [];

            for( var key in arr )
                availableOffers.push( arr[key] );

            var events = [];

            async.each(availableOffers, function( availableOffer, nextOffer ) {

                var eventObject = {
                    "eventType":"availableOffers",
{'fraction_non_alphanumeric': 0.12264644351464435, 'fraction_numerical': 0.0005230125523012552, 'mean_word_length': 1.7498202731847592, 'pattern_counts': {'":': 2, '<': 5, '<?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': '6460489', 'n_tokens_mistral': 1041, 'n_tokens_neox': 987, 'n_words': 229}