Giter Site home page Giter Site logo

swint-fork's People

Contributors

chosh31 avatar greenkeeper[bot] avatar kivol avatar plainoldcode avatar yihyunjoon avatar

Watchers

 avatar  avatar  avatar

swint-fork's Issues

Fork is not working when after process.nextTick

Issue is when "main process" send message to cluster.fork is called by async.
so worker need to send message "I am ready".
I think there is a API for this which is written by node.js but I can' find.
[https://nodejs.org/api/cluster.html]

please try this, I tested this code.

_.start = function() {
    var that = this;

    if (cluster.isMaster) {
        if (this.options.operator !== null) {
            this.options.operator.start(function() {
                that.startPreProcess();
            });
        } else {
            this.startPreProcess();
        }
    } else if (cluster.isWorker) {
        process.send({
            type: 'workerStart'
        })
    }

    process.on('message', function(msg) {
        switch (msg.type) {
            case 'control':
                switch (msg.data) {
                    case 'healthCheck':
                        that.monitor(function(err, res) {
                            if (err) {
                                print(4, err);
                                process.exit(-1);
                                return;
                            }
                            process.emit('controlEnd', null, res);
                        });
                        break;
                    case 'softReset':
                        that.resetPost(function(err) {
                            if (err) {
                                print(4, err);
                                process.exit(-1);
                                return;
                            }
                            process.emit('controlEnd');
                        });
                        break;
                    case 'hardReset':
                        that.resetAll(function(err) {
                            if (err) {
                                print(4, err);
                                process.exit(-1);
                                return;
                            }
                            process.emit('controlEnd');
                        });
                        break;
                }
                break;
            case 'data':
                that.options.postProcess(that, msg.data, function() {
                    process.send({
                        type: 'complete'
                    });
                });
                break;
        }
    });
};


_.createWorker = function(sharedData) {
    var that = this,
        worker = cluster.fork();

    worker.on('message', function(msg) {
        if (msg.type === 'complete') {
            that.evt.emit('complete');
        } else if (msg.type === 'workerStart') {
            worker.send({
                type: 'data',
                data: sharedData
            });
        }
    });

    return worker;
};

blocking event when soft reset is fired

case 'softReset':
    if(!that.resetPostRun){
        that.resetPost(function(err) {
            if (err) {
                print(4, err);
                process.exit(-1);
                return;
            }
            process.emit('controlEnd');
        }); 
    }

    break;
_.resetPost = function(callback) {
    var that = this,
        workers = [];

    this.resetPostRun = true;

    for (var id in cluster.workers) {
        var worker = cluster.workers[id];

        workers.push(worker);
    }

    async.series(
        workers.map(function(v) {
            return function(cb) {
                that.evt.once('complete', function() {
                    cb(null, true);
                });
                v.kill();
            };
        }),
        function(err) {
            callback(err, true);
            that.resetPostRun = false;
        }
    );
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.