refactor: catch errors from digest

isekai-main
Barış Soner Uşaklı 3 years ago
parent f7967bdf68
commit 8e319a9b25

@ -38,6 +38,7 @@ Digest.execute = async function (payload) {
winston.info(`[user/jobs] Digest (${payload.interval}) complete.`);
} catch (err) {
winston.error(`[user/jobs] Could not send digests (${payload.interval})\n${err.stack}`);
throw err;
}
};

@ -39,13 +39,17 @@ module.exports = function (User) {
function startDigestJob(name, cronString, term) {
jobs[name] = new cronJob(cronString, (async () => {
winston.verbose(`[user/jobs] Digest job (${name}) started.`);
if (name === 'digest.biweekly') {
const counter = await db.increment('biweeklydigestcounter');
if (counter % 2) {
User.digest.execute({ interval: term });
try {
if (name === 'digest.biweekly') {
const counter = await db.increment('biweeklydigestcounter');
if (counter % 2) {
await User.digest.execute({ interval: term });
}
} else {
await User.digest.execute({ interval: term });
}
} else {
User.digest.execute({ interval: term });
} catch (err) {
winston.error(err.stack);
}
}), null, true);
winston.verbose(`[user/jobs] Starting job (${name})`);

Loading…
Cancel
Save