我想看到發生的事情是讓MEAN旋轉了所有四個集羣。然後運行計劃的工作,每天20:30以電子郵件向我的客戶發送電子郵件。目前運行的次數不止一次。 我該如何做到這一點?MEANIO 4個羣集只能運行一次計劃的Job?
'use strict';
var mean = require('meanio');
var cluster = require('cluster');
var schedule = require('node-schedule');
var z = schedule.scheduleJob('30 20 * * *', function() {
console.log('test the scheduler')
});
if (cluster.isMaster) {
// Count the machine's CPUs
var cpuCount = require('os').cpus().length;
// Create a worker for each CPU
for (var i = 0; i < cpuCount; i += 1) {
console.log ('forking ',i);
cluster.fork();
}
// Listen for dying workers
cluster.on('exit', function (worker) {
// Replace the dead worker, we're not sentimental
console.log('Worker ' + worker.id + ' died :(');
cluster.fork();
});
} else {
var workerId = 0;
if (!cluster.isMaster)
{
workerId = cluster.worker.id;
}
mean.serve({ workerid: workerId /* more options placeholder*/ }, function (app, config) {
var port = config.https && config.https.port ? config.https.port : config.http.port;
console.log('Mean app started on port ' + port + ' (' + process.env.NODE_ENV + ') cluster.worker.id:', workerId);
});
}
輸出
forking 0
forking 1
forking 2
forking 3
Mean app started on port 3000 (development) cluster.worker.id: 1
Mean app started on port 3000 (development) cluster.worker.id: 2
Mean app started on port 3000 (development) cluster.worker.id: 3
Mean app started on port 3000 (development) cluster.worker.id: 4
test the scheduler
test the scheduler
test the scheduler
test the scheduler
test the scheduler