<commit_before>"use strict";
const spawn = require("child_process").spawn;
const portfinder = require("portfinder");
const ip = require("ip");

function startInstance(instance) {
  instance.port = portFromEndpoint(instance.endpoint);
  return new Promise((resolve, reject) => {
    let process = spawn(instance.binary, instance.args);

    process.stdout.on("data", data => {
      data.toString().split("\n").forEach(instance.logFn);
    });

    process.stderr.on("data", data => {
      data.toString().split("\n").forEach(instance.logFn);
    });
    process.on("close", code => {
      instance.status = "EXITED";
      instance.exitcode = code;

      // instance.logFn(`exited with code ${code}`);
    });
    instance.exitcode = null;
    instance.status = "RUNNING";
    instance.process = process;
    resolve(instance);
  });
}

let startMinPort = 40000;
if (process.env.PORT_OFFSET) {
  startMinPort += parseInt(process.env.PORT_OFFSET, 10);
}
let minPort = startMinPort;
let findFreePort = function(ip) {
  let startPort = minPort;
  minPort += 100;
  return portfinder.getPortPromise({ port: startPort, host: ip})
};

function portFromEndpoint(endpoint) {
  return endpoint.match(/:(\d+)\/?/)[1];
}

function createEndpoint() {
  let myIp = ip.address();

  return findFreePort(myIp).then(port => {
    return "tcp://" + myIp + ":" + port;
  });
}
<commit_msg>Change port to non dynamically used range (port clashes were frequent :S)<commit_after>"use strict";
const spawn = require("child_process").spawn;
const portfinder = require("portfinder");
const ip = require("ip");

function startInstance(instance) {
  instance.port = portFromEndpoint(instance.endpoint);
  return new Promise((resolve, reject) => {
    let process = spawn(instance.binary, instance.args);

    process.stdout.on("data", data => {
      data.toString().split("\n").forEach(instance.logFn);
    });

    process.stderr.on("data", data => {
      data.toString().split("\n").forEach(instance.logFn);
    });
    process.on("close", code => {
      instance.status = "EXITED";
      instance.exitcode = code;

      // instance.logFn(`exited with code ${code}`);
    });
    instance.exitcode = null;
    instance.status = "RUNNING";
    instance.process = process;
    resolve(instance);
  });
}

let startMinPort = 4000;
if (process.env.MIN_PORT) {
  startMinPort = parseInt(process.env.MIN_PORT, 10);
}

let portOffset = 50;
if (process.env.PORT_OFFSET) {
  portOffset = parseInt(process.env.PORT_OFFSET, 10);
}

let maxPort = 65535;
if (process.env.MAX_PORT) {
  maxPort = parseInt(process.env.MAX_PORT, 10);
}
let minPort = startMinPort;
let findFreePort = function(ip) {
  let startPort = minPort;
  minPort += portOffset;
  if (minPort >= maxPort) {
    minPort = startMinPort;
  }
  return portfinder.getPortPromise({ port: startPort, host: ip})
};

function portFromEndpoint(endpoint) {
  return endpoint.match(/:(\d+)\/?/)[1];
}

function createEndpoint() {
  let myIp = ip.address();

  return findFreePort(myIp).then(port => {
    return "tcp://" + myIp + ":" + port;
  });
}

{'fraction_non_alphanumeric': 0.16644993498049415, 'fraction_numerical': 0.00942782834850455, 'mean_word_length': 3.8456692913385826, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 14, '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': '1133426', 'n_tokens_mistral': 1008, 'n_tokens_neox': 977, 'n_words': 204}