more robust send loop
This commit is contained in:
parent
8efc0065e6
commit
3d901852ab
|
@ -31,10 +31,17 @@ var EMAIL_TYPES = {
|
|||
|
||||
|
||||
function EmailService(opts) {
|
||||
$.checkArgument(opts);
|
||||
|
||||
opts.email = opts.email || {};
|
||||
|
||||
this.storage = opts.storage;
|
||||
this.lock = opts.lock;
|
||||
this.mailer = opts.mailer || nodemailer.createTransport(opts.email);
|
||||
this.from = opts.email.from;
|
||||
|
||||
$.checkState(this.mailer);
|
||||
$.checkState(this.from);
|
||||
};
|
||||
|
||||
// TODO: cache for X minutes
|
||||
|
@ -95,7 +102,7 @@ EmailService.prototype._getDataForTemplate = function(notification, cb) {
|
|||
data.walletM = wallet.m;
|
||||
data.walletN = wallet.n;
|
||||
var copayer = _.find(wallet.copayers, {
|
||||
copayerId: notification.creatorId
|
||||
id: notification.creatorId
|
||||
});
|
||||
if (copayer) {
|
||||
data.creatorId = copayer.id;
|
||||
|
@ -162,6 +169,7 @@ EmailService.prototype.sendEmail = function(notification, cb) {
|
|||
var email = Model.Email.create({
|
||||
walletId: notification.walletId,
|
||||
copayerId: recipient.copayerId,
|
||||
from: self.from,
|
||||
to: recipient.emailAddress,
|
||||
subject: content.subject,
|
||||
body: content.body,
|
||||
|
@ -174,7 +182,9 @@ EmailService.prototype.sendEmail = function(notification, cb) {
|
|||
function(emails, next) {
|
||||
async.each(emails, function(email, next) {
|
||||
self._send(email, next);
|
||||
}, next);
|
||||
}, function(err) {
|
||||
return next();
|
||||
});
|
||||
},
|
||||
], cb);
|
||||
};
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
'use strict';
|
||||
|
||||
var _ = require('lodash');
|
||||
var Uuid = require('uuid');
|
||||
|
||||
function Email() {
|
||||
this.version = '1.0.0';
|
||||
};
|
||||
|
@ -9,7 +12,9 @@ Email.create = function(opts) {
|
|||
|
||||
var x = new Email();
|
||||
|
||||
x.createdOn = Math.floor(Date.now() / 1000);
|
||||
var now = Date.now();
|
||||
x.createdOn = Math.floor(now / 1000);
|
||||
x.id = _.padLeft(now, 14, '0') + Uuid.v4();
|
||||
x.walletId = opts.walletId;
|
||||
x.copayerId = opts.copayerId;
|
||||
x.from = opts.from;
|
||||
|
@ -26,6 +31,7 @@ Email.fromObj = function(obj) {
|
|||
var x = new Email();
|
||||
|
||||
x.createdOn = obj.createdOn;
|
||||
x.id = obj.id;
|
||||
x.walletId = obj.walletId;
|
||||
x.copayerId = obj.copayerId;
|
||||
x.from = obj.from;
|
||||
|
|
|
@ -245,7 +245,7 @@ describe('Wallet service', function() {
|
|||
// uri: 'mongodb://localhost:27017/bws_test'
|
||||
// }
|
||||
// }, done);
|
||||
});
|
||||
});
|
||||
beforeEach(function(done) {
|
||||
resetDb(function() {
|
||||
blockchainExplorer = sinon.stub();
|
||||
|
@ -254,6 +254,9 @@ describe('Wallet service', function() {
|
|||
storage: storage,
|
||||
blockchainExplorer: blockchainExplorer,
|
||||
mailer: mailer,
|
||||
email: {
|
||||
from: 'bws@dummy.net',
|
||||
}
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue