node-js-libs / node.io

MIT License
1.81k stars 140 forks source link

Running node.io job programmatically within a cron job: node.io.start() won't restart. #123

Closed yichen closed 9 years ago

yichen commented 11 years ago

Hello,

I need to run a node.io job with a schedule. Instead of using the OS native crontab I am using the node-cron module from within my nodejs application, using this command:

nodeio.start(job, options, callback, capture_output)

What I noticed is that this above line will work when it was called for the first time. It did nothing when it is called for subsequent scheduled run. Any ideas? It seems the nodeio.start() will only start a node.io job for once and cannot be called repeatedly?

Thanks!

chriso commented 11 years ago

How are you calling the function? Make sure you provide a callback, as the default behaviour otherwise is to exit the process.

Here's an example of running the same job indefinitely

var nodeio = require('node.io')
  , iterations = 1;

var job = new nodeio.Job({
    input: [ 1 ],
    run: function () {
        this.emit('At iteration ' + (iterations++));
    }
});

(function startJob() {
    nodeio.start(job, { silent: true }, function (err, output) {
        console.log(output);
        process.nextTick(startJob);
    }, true);
})();
laurentdebricon commented 11 years ago

Hello, by reusing a job, I have this problem : (remember me ? https://github.com/chriso/node.io/pull/114#issuecomment-7769027 )

I did what you told me, use globales. But this line is still often failing :

var job_id = utils.crc32(JSON.stringify(job)); l.270 of processor.js

because of job.output_streams which can't be stringified .

here is a screenpic of my debugger at that moment : http://i46.tinypic.com/2laatz6.png

Maybe http://stackoverflow.com/questions/9577200/does-a-writestream-have-to-be-closed ?

Cheers !