mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-14 02:27:49 +01:00
fix: closes #13258, dont mark digest as delivered if it fails
show fail count and sent count separately
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user