<commit_before>"use strict";
let async = require('async');
let consulClient = null;
let restifyLib = null;
let addressCache = {};
let refreshWindow = 5;
let refreshStatus = {};
let maximumConcurrentUpdates = 1;

function performGetAddressForService(service, callback) {
	return consulClient.health.service({
		service: service,
		passing: true
	}, function(err, results) {
		if (err) return callback(err, null);
		let endpoints = [];
		let endpointObj = {};
		results.forEach(function(entry) {
			let obj = {
				address: entry.Service.Address,
				port: entry.Service.Port,
				tags: entry.Service.Tags,
				id: entry.Service.ID,
				fullAddress: entry.Service.Address + ':' + entry.Service.Port,
			}
			if (endpointObj[obj.fullAddress] === undefined) {
				endpointObj[obj.fullAddress] = true;
				endpoints.push(obj);
			}
		});
		addressCache[service] = endpoints;
		return callback(null, endpoints);
	});
}

function getAddresesForService(service, callback) {
	let statusObj = refreshStatus[service];
	if (statusObj === undefined) {
		refreshStatus[service] = {
			status: 'waiting',
			callbacks: [],
		}
		statusObj = refreshStatus[service];
	}
	statusObj.callbacks.push(callback);
	if (statusObj.status === 'waiting') {
		statusObj.status = 'pending';
		performGetAddressForService(service, function(err, endpoints) {
			statusObj.callbacks.forEach(function(callback) {
				return callback(err, endpoints);
			});
			statusObj.callbacks.splice(0, refreshStatus.callbacks.length);
			statusObj.status = 'waiting';
		});
	}
}

exports.getAddresesForService = getAddresesForService;

function buildClient(service, callback) {
	let addresses = addressCache[service];
	let address = addresses[Math.floor(Math.random() * addresses.length)];
	let url = 'http://' + address.address + ":" + address.port;
	return callback(null, restify.createJsonClient({
	  url:  url,
	}));
}

function refreshAddresses() {
	let services = Object.keys(addressCache);
	if (Object.keys(addressCache).length === 0) {
		return setRefreshTimer();
	}
	async.eachLimit(services, maximumConcurrentUpdates, <commit_msg>incorrect object reference in getAddressesForService...again<commit_after>"use strict";
let async = require('async');
let consulClient = null;
let restifyLib = null;
let addressCache = {};
let refreshWindow = 5;
let refreshStatus = {};
let maximumConcurrentUpdates = 1;

function performGetAddressForService(service, callback) {
	return consulClient.health.service({
		service: service,
		passing: true
	}, function(err, results) {
		if (err) return callback(err, null);
		let endpoints = [];
		let endpointObj = {};
		results.forEach(function(entry) {
			let obj = {
				address: entry.Service.Address,
				port: entry.Service.Port,
				tags: entry.Service.Tags,
				id: entry.Service.ID,
				fullAddress: entry.Service.Address + ':' + entry.Service.Port,
			}
			if (endpointObj[obj.fullAddress] === undefined) {
				endpointObj[obj.fullAddress] = true;
				endpoints.push(obj);
			}
		});
		addressCache[service] = endpoints;
		return callback(null, endpoints);
	});
}

function getAddresesForService(service, callback) {
	let statusObj = refreshStatus[service];
	if (statusObj === undefined) {
		refreshStatus[service] = {
			status: 'waiting',
			callbacks: [],
		}
		statusObj = refreshStatus[service];
	}
	statusObj.callbacks.push(callback);
	if (statusObj.status === 'waiting') {
		statusObj.status = 'pending';
		performGetAddressForService(service, function(err, endpoints) {
			statusObj.callbacks.forEach(function(callback) {
				return callback(err, endpoints);
			});
			statusObj.callbacks.splice(0, statusObj.callbacks.length);
			statusObj.status = 'waiting';
		});
	}
}

exports.getAddresesForService = getAddresesForService;

function buildClient(service, callback) {
	let addresses = addressCache[service];
	let address = addresses[Math.floor(Math.random() * addresses.length)];
	let url = 'http://' + address.address + ":" + address.port;
	return callback(null, restify.createJsonClient({
	  url:  url,
	}));
}

function refreshAddresses() {
	let services = Object.keys(addressCache);
	if (Object.keys(addressCache).length === 0) {
		return setRefreshTimer();
	}
	async.eachLimit(services, maximumConcurrentUpdates, 
{'fraction_non_alphanumeric': 0.13873788702434411, 'fraction_numerical': 0.0018908059560387616, 'mean_word_length': 4.76566757493188, 'pattern_counts': {'":': 2, '<': 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': '3338705', 'n_tokens_mistral': 1450, 'n_tokens_neox': 1309, 'n_words': 268}