Skip to content

Commit

Permalink
fix: log error if bad mongo connection, resolves #997
Browse files Browse the repository at this point in the history
Small tweaks
  • Loading branch information
Ilya Radchenko committed Feb 20, 2017
1 parent 9948980 commit 04cdefb
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ exports.init = function (config) {

mongoose.connect(mongodbUrl, function (error) {
if (error) {
debug('Could not connect to DB: %s', error);
console.log('Could not connect to DB: %s', error);
process.exit(1);
}
});
Expand Down
1 change: 0 additions & 1 deletion lib/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ var text = loadTemplates(templates, 'plaintext');
/*
* loading all of the email templates at server start
*/

function loadTemplates(list, type) {
if (!list) {
return;
Expand Down
1 change: 0 additions & 1 deletion lib/humane.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

exports.humaneDate = function humaneDate(date, compareTo) {

if (!date) {
return;
}
Expand Down
28 changes: 19 additions & 9 deletions lib/jobs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,31 @@ module.exports = {
small: small
};

var async = require('async');
var Job = require('./models').Job;
var User = require('./models').User;
var Project = require('./models').Project;
var utils = require('./utils');
var async = require('async');

var TEST_ONLY = 'TEST_ONLY';

// user: user object
// small: if true, "phases" and "std" will not be fetched for the jobs
// - dramatically reducing the size of the object.
// TODO: add paging
// done(err, {yours: [...], public: [...]})
/**
* user: user object
* small: if true, "phases" and "std" will not be fetched for the jobs
* - dramatically reducing the size of the object.
* TODO: add paging
* done(err, {yours: [...], public: [...]})
*
* @param {Object} user
* @param {Boolean} small
* @param {Function} done
*/
function latestJobs(user, small, done) {
if (arguments.length === 2) {
done = small;
small = false;
}
var tasks = {public: latestPublicJobs.bind(null, user, small)};
var tasks = { public: latestPublicJobs.bind(null, user, small) };
if (user) {
tasks.yours = latestUsersJobs.bind(null, user, small);
}
Expand Down Expand Up @@ -75,10 +81,14 @@ function latestJob(project, user, small, done) {
.sort({finished: -1})
.limit(6)
.lean();
if (small) query = query.select('-phases -std');

if (small) {
query = query.select('-phases -std');
}

query.exec(function (err, jobs) {
if (!jobs || !jobs.length) {
return done(err, {nojobs: true, project: jobProject(project, [], user)});
return done(err, { nojobs: true, project: jobProject(project, [], user) });
}
var job = jobs[0];
job.project = jobProject(project, jobs.slice(1));
Expand Down

0 comments on commit 04cdefb

Please sign in to comment.