我正在使用节点议程模块来启动用户创建的各种工作/事件。我希望能够创建作业,以便所有这些都由一个函数回调处理,每个事件都根据事件参数进行区分。下面的示例代码
var mongoConnectionString = "mongodb://127.0.0.1/agenda";
var Agenda = require('agenda');
var agenda = new Agenda({db: {address: mongoConnectionString}});
agenda.define('user defined event', function(job,done) {
var eventParams = job.attrs.data;
if(eventParams.params === "Test"){
handleEvent1();
} else if (eventParams.params === "Test 2") {
handleEvent2();
} else {
handleEvent3();
}
done();
});
agenda.on('ready', function() {
console.log("Ok Lets get start");
agenda.start();
});
// some how we get our call back executed. Note that params is the unique to each job.
var userEvent = function(params) {
// Handle a event which repeats every 10 secs
agenda.every('10 seconds','user defined event',params);
}
使用此代码,mongodb 中的作业将更新而不是插入。有什么办法可以强制插入议程而不是更新?如果议程不可能,是否还有其他模块可以做到这一点?
提前感谢您的宝贵时间