<commit_before>var cp = require("child_process"),
    _ = require("underscore"),
    uuid = require("node-uuid"),
    C = require("./constants");


module.exports = function (opts) {

    //opts.worker.file, opts.worker.count, opts.worker.restarts
    //opts.request.retries (-1 || positive number), opts.request.timeout (-1 || positive number ms)

    var sp = new Object();
    var workers = new Array(),
        requests = new Array,
        killing = false;


    function handleMessage(worker, msg) {
        //READY

        //HEALTH

        //OTHER

        //REQUEST -> find idRequest ? -> if yes, call cb, clear timeout, delete request

        //spread
    };

    function handleExit(worker, code, signal) {

        //worker = removeWorker()

        //If mode soft-kill, we do nothing if still workers alive, if all are killed, we kill supervisor

        //If worker still accepts restarts, do it

        //Let's take all requests that enable retries, minus them, resend them

    };

    function listen(worker) {
        worker.process.on("message", function (msg) {
            return handleMessage(worker, msg);
        });
        worker.process.on("exit", function (code, signal) {
            return handleExit(worker, code, signal);
        });
    };

    function createWorker() {<commit_msg>feat(supervisor): handle communication between worker and supervisor<commit_after>var cp = require("child_process"),
    _ = require("underscore"),
    uuid = require("node-uuid"),
    C = require("./constants"),
    debug = require('debug')('lpm:supervisor'),
    utils = require('./utilities');


module.exports = function (opts) {

    //opts.worker.file, opts.worker.count, opts.worker.restarts
    //opts.request.retries (-1 || positive number), opts.request.timeout (-1 || positive number ms)

    var sp = new Object();
    var workers = new Array(),
        requests = new Array,
        killing = false,
        workersOnlineTriggered = false;


    function handleMessage(worker, msg) {
        if (typeof msg.event !== 'string' ||
            msg.event.indexOf(C.NAMESPACE) === -1 ||
            (msg.event === C.REQUEST && typeof msg.id !== 'string')) {
            debug('Message not belonging to LPM: %o', msg);
            return;
        }
        switch (msg.event) {
            case C.READY:
                worker.reay = true;
                if (!workersOnlineTriggered) {
                    checkIfAllWorkersReady();
                }
                break;
            case C.HEALTH:
                worker.health = msg.memoryUsage;
                break;
            case C.BUSY:
                worker.ready = false;
                break;
            case C.RESPONSE:
                for (var i = 0; i < worker.requests.length; i++) {
                    var req = worker.requests[i];
                    if (req.id !== msg.id) {
                        continue;
                    }
                    debug('Resolving %s with %o', msg.id, msg.data);
                    if (typeof req.callback.original === 'function') {
                        req.callback.original(msg.data);
                    }
                    req.callback.defer.resolve(msg.data);
                    clearTimeout(req.timeout);
                    worker.requests.splice(i, 1);
                    break;
                }
                break;
        }
        if (msg.event.indexOf(C.OTHER) > -1) {
            utils.trigger(msg.event.replace(C.OTHER, ''), msg.data);
        }
        spreadRequests();
    };

    function checkIfAllWorkersReady() {
        var allReady = true;
        workers.forEach(function (w) {
            if (w.ready !== true) {
                allReady = false;
            }
        });
        if (allReady) {
            workersOnlineTriggered = true;
            utils.trigger('online');
        }
    }

    function handleExit(worker, code, signal) {

        //worker = removeWorker()

        //If mode soft-kill, we do nothing if still workers alive, if all are killed, we kill supervisor

        //If worker still accepts restarts, do it

        //Let's take all requests that enable retries, minus them, resend them

    };

    function listen(worker) {
        worker.process.on("message", function (msg) {
            return handleMessage(worker, msg);
        });
        worker.process.on("exit", function (code, signal) {
            return handleExit(worker, code, signal);
        });
    };

    function createWorker() {
{'fraction_non_alphanumeric': 0.12372278987116837, 'fraction_numerical': 0.001776988005330964, 'mean_word_length': 1.6915720263000598, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, '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': '2082211', 'n_tokens_mistral': 1234, 'n_tokens_neox': 1164, 'n_words': 318}