议程预定作业 运行 仅一次
Agenda scheduled job running only once
我有一个开始使用 Agenda 的示例程序,它在第一次 运行 后卡住了。
var Agenda = require('agenda');
var agenda = new Agenda({db: {address: 'localhost/sample-dev', collection: 'pollingJob'}});
agenda.define('First1', function(job, done) {
var d = new Date();
console.log("Hello First Job at " + d );
});
agenda.on('ready', function() {
agenda.every('5 seconds', 'First1');
agenda.start();
});
我已经按照 Agenda 上的说明完成了所有操作,我是否遗漏了什么?
来自docs,
When a job of job name gets run, it will be passed to fn(job, done).
To maintain asynchronous behavior, you must call done() when you are
processing the job. If your function is synchronous, you may omit done
from the signature.
所以,从上面省略回调和re-define作为同步作业的基本示例,如下所示:
agenda.define('First1', function(job) {
var d = new Date();
console.log("Hello First Job at " + d );
});
agenda.on('ready', function() {
agenda.every('5 seconds', 'First1');
agenda.start();
});
我有一个开始使用 Agenda 的示例程序,它在第一次 运行 后卡住了。
var Agenda = require('agenda');
var agenda = new Agenda({db: {address: 'localhost/sample-dev', collection: 'pollingJob'}});
agenda.define('First1', function(job, done) {
var d = new Date();
console.log("Hello First Job at " + d );
});
agenda.on('ready', function() {
agenda.every('5 seconds', 'First1');
agenda.start();
});
我已经按照 Agenda 上的说明完成了所有操作,我是否遗漏了什么?
来自docs,
When a job of job name gets run, it will be passed to fn(job, done). To maintain asynchronous behavior, you must call done() when you are processing the job. If your function is synchronous, you may omit done from the signature.
所以,从上面省略回调和re-define作为同步作业的基本示例,如下所示:
agenda.define('First1', function(job) {
var d = new Date();
console.log("Hello First Job at " + d );
});
agenda.on('ready', function() {
agenda.every('5 seconds', 'First1');
agenda.start();
});