我想看到发生的事情是让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