gpt4 book ai didi

javascript - 使用 'agenda' 时,Nodemon 在启动时崩溃且无踪迹

转载 作者:搜寻专家 更新时间:2023-11-01 00:00:50 25 4
gpt4 key购买 nike

RESOLVED:

要解决此问题,需要更改以下答案,但请注意,如果使用 nodemon/grunt-nodemon 存在另一个问题,其中 1.2.x 出于某种原因使控制台输出静音,因此如果使用控制台进行测试,它将无法正常工作. 1.3.x 已修复、更新并解决任何依赖性问题。我最终将下面的固定代码移到了我的 app = express() 行下。并将任何 agenda-ui 行与我的其余 app.use() 中间件放在一起。

此外,如果使用 agenda-ui,则会引入一些中断,在尝试访问/agenda-ui 端点时会返回“无法读取未定义的属性”。还不知道为什么,但有一个开放的错误报告。

ORIGINAL POST

我知道我是这里的问题。我已经构建了一个应用程序并想使用“议程”进行后端作业调度。应用程序在 server.js 中没有议程行时工作正常。它直接在议程的 github 页面上说没有推荐的布局,因此尝试通过在我的 server.js 中插入它来测试基本功能一开始似乎是可行的。

Nodemon 启动并立即因错误而崩溃,但没有关于原因的痕迹或信息。启动:

[nodemon] v1.2.1 [nodemon] to restart at any time, enter rs [nodemon] watching: app/views//. gruntfile.js server.js config//*.js app/**/*.js
[nodemon] starting node --debug server.js
[nodemon] app crashed - waiting for file changes before starting...

我把议程代码放在最后我会说在一些基本测试之后应用程序不会崩溃直到这两行被取消注释。我认为这可能与我的连接字符串有关,因为这是我已经连接到主应用程序的数据库的名称。但我又一次用完了可供借鉴的信息。

agenda.schedule('in 10 seconds', 'greet the world', {time: new Date()});
agenda.start();

    'use strict';
/**
* Module dependencies.
*/
var init = require('./config/init')(),
config = require('./config/config'),
mongoose = require('mongoose'),
chalk = require('chalk'),
Agenda = require('agenda');


/**
* Main application entry file.
* Please note that the order of loading is important.
*/

// Bootstrap db connection
var db = mongoose.connect(config.db, function(err) {
if (err) {
console.error(chalk.red('Could not connect to MongoDB!'));
console.log(chalk.red(err));
}
});

// Init the express application
var app = require('./config/express')(db);

// Bootstrap passport config
require('./config/passport')();

// Start the app by listening on <port>
app.listen(config.port);

// Expose app
exports = module.exports = app;

// Logging initialization
console.log('Application started on port ' + config.port);


/////--------TESTING----------------
var agenda = new Agenda({
db: {
address: 'mongodb://localhost/consultations',
collection: 'emailQueue'
//options: {
// ssl: true
//}
}
});

agenda.define('greet the world', function(job, done) {
console.log(job.attrs.data.time, 'hello world!');
done();
});

agenda.schedule('in 10 seconds', 'greet the world', {time: new Date()});
agenda.start();

console.log('Wait 10 seconds...');
//////------------------------

最佳答案

试试这个

agenda.on('ready', function() {
agenda.define('greet the world', function(job, done) {
console.log(job.attrs.data.time, 'hello world!');
done();
});

agenda.schedule('in 10 seconds', 'greet the world', {
time: new Date()
});
agenda.start();
});

我也有类似的数据库

var agenda = new Agenda({
db: {
address: 'localhost:27017/test' //default collection agendaJobs
}
});

希望对您有所帮助

关于javascript - 使用 'agenda' 时,Nodemon 在启动时崩溃且无踪迹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33810898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com