Merge pull request #11562 from HabitRPG/sabrecat/bulk-email-fix

Better promise handling for bulk emailing
This commit is contained in:
Matteo Pagliazzi 2019-11-25 16:48:15 +01:00 committed by GitHub
commit 8983e7fea2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 3 deletions

View file

@ -16,7 +16,7 @@ async function updateUser (user) {
if (count % progressCount === 0) console.warn(`${count} ${user._id}`);
sendTxn(
await sendTxn(
user,
EMAIL_SLUG,
[{ name: 'BASE_URL', content: BASE_URL }], // Add variables from template

View file

@ -66,7 +66,7 @@ export function getGroupUrl (group) {
}
// Send a transactional email using Mandrill through the external email server
export function sendTxn (mailingInfoArray, emailType, variables, personalVariables) {
export async function sendTxn (mailingInfoArray, emailType, variables, personalVariables) {
mailingInfoArray = Array.isArray(mailingInfoArray) ? mailingInfoArray : [mailingInfoArray]; // eslint-disable-line no-param-reassign, max-len
variables = [ // eslint-disable-line no-param-reassign, max-len
@ -130,7 +130,7 @@ export function sendTxn (mailingInfoArray, emailType, variables, personalVariabl
}
if (IS_PROD && mailingInfoArray.length > 0) {
got.post(`${EMAIL_SERVER.url}/job`, {
return got.post(`${EMAIL_SERVER.url}/job`, {
auth: `${EMAIL_SERVER.auth.user}:${EMAIL_SERVER.auth.password}`,
json: true,
body: {
@ -149,4 +149,6 @@ export function sendTxn (mailingInfoArray, emailType, variables, personalVariabl
},
}).catch(err => logger.error(err));
}
return null;
}