<commit_before>var os = require("os");
var _ = require("lodash");
var dockerode = require("dockerode");
var retry = require("./util/retry.js");

var argv = require("yargs")
        .demand("consulHost")
        .default("consulPort", 8500)
        .argv;

var consul = require("consul")({
    host: argv.consulHost,
    port: argv.consulPort
});

var containerData = {};

var docker = dockerode({socketPath: '/var/run/docker.sock'});

var workQueue = require("./work-queue.js")();

main();

function main () {
    var events = require("./service-events.js")(docker);

    events.on("start", function (service) {
        workQueue.push(function (done) {
            registerService(service, done);
        });
    });

    events.on("stop", function (service) {
        workQueue.push(function (done) {
            unregisterService(service, done);
        });
    });

    events.on("theEnd", function () {
        console.log("Not more events from docker. Exiting...");
        process.exit(1);
    });
}

function registerService (service, done) {
    var obj = {
        name: service.properties.name,
        id:   serviceId(service),
        tags: serviceTags(service),
        address: service.ip,
        port: service.port
    };
    console.log("registering", obj.id);
    retry.retryWithThrottling(function (retry) {
        consul.agent.service.register(obj, function (err) {
            if (err) {
                retry(err);
            } else {
                console.log("registered", obj.id);
                done();
            }
        });
    }, {
        maxAttempts: 5,
        failProc: function (err) {
            console.log(err);
            done();
        }
    });
}

function serviceId (service) {
    return [
        "registrator",
        os.hostname(),
        service.properties.name,
        service.properties.descriminator
    ].filter(_.identity).join(":");
}<commit_msg>Remove hostname from service id<commit_after>var os = require("os");
var _ = require("lodash");
var dockerode = require("dockerode");
var retry = require("./util/retry.js");

var argv = require("yargs")
        .demand("consulHost")
        .default("consulPort", 8500)
        .argv;

var consul = require("consul")({
    host: argv.consulHost,
    port: argv.consulPort
});

var containerData = {};

var docker = dockerode({socketPath: '/var/run/docker.sock'});

var workQueue = require("./work-queue.js")();

main();

function main () {
    var events = require("./service-events.js")(docker);

    events.on("start", function (service) {
        workQueue.push(function (done) {
            registerService(service, done);
        });
    });

    events.on("stop", function (service) {
        workQueue.push(function (done) {
            unregisterService(service, done);
        });
    });

    events.on("theEnd", function () {
        console.log("Not more events from docker. Exiting...");
        process.exit(1);
    });
}

function registerService (service, done) {
    var obj = {
        name: service.properties.name,
        id:   serviceId(service),
        tags: serviceTags(service),
        address: service.ip,
        port: service.port
    };
    console.log("registering", obj.id);
    retry.retryWithThrottling(function (retry) {
        consul.agent.service.register(obj, function (err) {
            if (err) {
                retry(err);
            } else {
                console.log("registered", obj.id);
                done();
            }
        });
    }, {
        maxAttempts: 5,
        failProc: function (err) {
            console.log(err);
            done();
        }
    });
}

function serviceId (service) {
    return [
        "registrator",
        // os.hostname(),
        service.properties.name,
        service.properties.descriminator
    ].filter(_.identity).join(":");
}
{'fraction_non_alphanumeric': 0.1576072821846554, 'fraction_numerical': 0.0031209362808842654, 'mean_word_length': 2.1524590163934425, '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': '1471850', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1137, 'n_words': 222}