我想使用带有nodejs的议程安排一个简单的任务,但是当它被包装在apiRoutes(快速路由器)中时它没有执行
var apiRoutes = express.Router();
app.use('/api', apiRoutes);
apiRoutes.post('/scheduler/submit', function (req, res) {
agenda.define('test', function () {
console.log('Test');
});
agenda.on('ready', function () {
agenda.every('*/1 * * * *', 'test');
agenda.start();
});
});
但是,如果我将该代码放在外面,它仍然可以工作。嗯,有什么想法吗?
var apiRoutes = express.Router();
app.use('/api', apiRoutes);
agenda.define('test', function () {
console.log('Test');
});
agenda.on('ready', function () {
agenda.every('*/1 * * * *', 'test');
agenda.start();
});
apiRoutes.post('/scheduler/submit', function (req, res) {
// Leave blank
});