使用 'agenda' 时,Nodemon 在启动时崩溃且没有任何痕迹

Nodemon crashing on start with no trace when using 'agenda'

RESOLVED:

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

此外,如果使用 agenda-ui,则会在尝试访问 /agenda-ui 端点时引入一些中断 return "cannot read property of undefined"。还不知道为什么,但有一个开放的错误报告。

ORIGINAL POST

我知道我是问题所在。我有一个应用程序 ui,想使用 'agenda' 进行后端作业调度。在 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
    } 
});

希望对您有所帮助