Added catch for cron error (#8864)

* Added catch for cron error

* Updated logger usage
This commit is contained in:
Keith Holliday
2017-07-12 14:35:08 -06:00
committed by Sabe Jones
parent 7a2432a1a0
commit 28b56256d2

View File

@@ -5,6 +5,7 @@ import { model as Group } from '../models/group';
import { model as User } from '../models/user'; import { model as User } from '../models/user';
import { recoverCron, cron } from '../libs/cron'; import { recoverCron, cron } from '../libs/cron';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
import logger from '../libs/logger';
async function cronAsync (req, res) { async function cronAsync (req, res) {
let user = res.locals.user; let user = res.locals.user;
@@ -106,13 +107,17 @@ async function cronAsync (req, res) {
await recoverCron(recoveryStatus, res.locals); await recoverCron(recoveryStatus, res.locals);
} else { } else {
logger.error(err, {isUserUpdateErroringDuringCron: true});
// For any other error make sure to reset _cronSignature so that it doesn't prevent cron from running // For any other error make sure to reset _cronSignature so that it doesn't prevent cron from running
// at the next request // at the next request
await User.update({ await User.update({
_id: user._id, _id: user._id,
}, { }, {
_cronSignature: 'NOT_RUNNING', _cronSignature: 'NOT_RUNNING',
}).exec(); }).exec()
.catch((newError) => {
logger.error(newError, {isUserUpdateErroringDuringCron: true});
});
throw err; // re-throw the original error throw err; // re-throw the original error
} }