RESOLVED:
Changes in the answer below needed to happen for this to get resolved although as a note there's another issue if using nodemon / grunt-nodemon where 1.2.x silences console output for some reason so if testing with console it won't work. 1.3.x has the fix, Update and resolve any dependency issues. I ended up moving the fixed code below to under my app = express() line. And placed any agenda-ui lines with the rest of my app.use() middleware.
Also if using agenda-ui some breaking have been introduced that return a "cannot read property of undefined" when trying to hit the /agenda-ui endpoint. Not sure why yet but there is an open bug report.
ORIGINAL POST
I KNOW that I'm the problem here. I have built an app and want to use 'agenda' for backend job scheduling. App works fine without agenda lines in server.js. It says directly on the github page for agenda that there's no recommended layout, so trying to test the basic functionality by chuckin' it in my server.js seemed viable at first.
Nodemon starts up and crashes immediately with error but with no trace or information as to why. Startup:
[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] startingnode --debug server.js
[nodemon] app crashed - waiting for file changes before starting...
I threw the agenda code in at the end I will say after some basic testing the app does NOT crash until these 2 lines are uncommented. I thought maybe it was something to do with my connection string, as that's the name of the database I'm already connected to for the main app. But again I ran out of information to draw from.
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...');
//////------------------------
try this
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();
});
also i had db like
var agenda = new Agenda({
db: {
address: 'localhost:27017/test' //default collection agendaJobs
}
});
hope it helps