fix: closes #13258, dont mark digest as delivered if it fails

show fail count and sent count separately
This commit is contained in:
Barış Soner Uşaklı
2026-01-22 11:31:59 -05:00
parent 3272ea576f
commit f29c9f064b

View File

@@ -84,6 +84,7 @@ Digest.getSubscribers = async function (interval) {
Digest.send = async function (data) {
let emailsSent = 0;
let emailsFailed = 0;
if (!data || !data.subscribers || !data.subscribers.length) {
return emailsSent;
}
@@ -100,6 +101,7 @@ Digest.send = async function (data) {
return;
}
const userSettings = await user.getMultipleUserSettings(userData.map(u => u.uid));
const successfullUids = [];
await Promise.all(userData.map(async (userObj, index) => {
const userSetting = userSettings[index];
const [publicRooms, notifications, topics] = await Promise.all([
@@ -124,34 +126,39 @@ Digest.send = async function (data) {
}
});
emailsSent += 1;
await emailer.send('digest', userObj.uid, {
subject: `[[email:digest.subject, ${date.toLocaleDateString(userSetting.userLang)}]]`,
username: userObj.username,
userslug: userObj.userslug,
notifications: unreadNotifs,
publicRooms: publicRooms,
recent: topics.recent,
topTopics: topics.top,
popularTopics: topics.popular,
interval: data.interval,
showUnsubscribe: true,
}).catch((err) => {
try {
await emailer.send('digest', userObj.uid, {
subject: `[[email:digest.subject, ${date.toLocaleDateString(userSetting.userLang)}]]`,
username: userObj.username,
userslug: userObj.userslug,
notifications: unreadNotifs,
publicRooms: publicRooms,
recent: topics.recent,
topTopics: topics.top,
popularTopics: topics.popular,
interval: data.interval,
showUnsubscribe: true,
});
emailsSent += 1;
successfullUids.push(userObj.uid);
} catch (err) {
emailsFailed += 1;
if (!errorLogged) {
winston.error(`[user/jobs] Could not send digest email\n[emailer.send] ${err.stack}`);
errorLogged = true;
}
});
}
}));
if (data.interval !== 'alltime') {
if (data.interval !== 'alltime' && successfullUids.length) {
const now = Date.now();
await db.sortedSetAdd('digest:delivery', userData.map(() => now), userData.map(u => u.uid));
await db.sortedSetAdd('digest:delivery', successfullUids.map(() => now), successfullUids);
}
}, {
interval: 1000,
batch: 100,
});
winston.info(`[user/jobs] Digest (${data.interval}) sending completed. ${emailsSent} emails sent.`);
winston.info(`[user/jobs] Digest (${data.interval}) sending completed. ${emailsSent} emails sent. ${emailsFailed} failures.`);
return emailsSent;
};