|
|
@ -204,6 +204,14 @@ EmailService.prototype.sendEmail = function(notification, cb) { |
|
|
|
self._getRecipientsList(notification, emailType, function(err, recipientsList) { |
|
|
|
if (_.isEmpty(recipientsList)) return cb(); |
|
|
|
|
|
|
|
// TODO: Optimize so one process does not have to wait until all others are done
|
|
|
|
// Instead set a flag somewhere in the db to indicate that this process is free
|
|
|
|
// to serve another request.
|
|
|
|
self.lock.runLocked('email-' + notification.id, cb, function(cb) { |
|
|
|
self.storage.fetchEmailByNotification(notification.id, function(err, email) { |
|
|
|
if (err) return cb(err); |
|
|
|
if (email) return cb(); |
|
|
|
|
|
|
|
async.waterfall([ |
|
|
|
|
|
|
|
function(next) { |
|
|
@ -231,6 +239,7 @@ EmailService.prototype.sendEmail = function(notification, cb) { |
|
|
|
to: recipient.emailAddress, |
|
|
|
subject: content.subject, |
|
|
|
body: content.body, |
|
|
|
notificationId: notification.id, |
|
|
|
}); |
|
|
|
self.storage.storeEmail(email, function(err) { |
|
|
|
return next(err, email); |
|
|
@ -258,6 +267,8 @@ EmailService.prototype.sendEmail = function(notification, cb) { |
|
|
|
return cb(err); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
module.exports = EmailService; |
|
|
|