mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-22 02:11:44 +03:00
f4fdb4fa6c
fixes https://github.com/TryGhost/Team/issues/2310 This moves the processing of the events from the event-processor to a new email-event-processor in the email-service package. - The `EmailEventProcessor` only translates events from providerId/emailId to their known emailId, memberId and recipientId, and dispatches the corresponding events. - Since `EmailEventProcessor` runs in a separate worker thread, we can't listen for the dispatched events on the main thread. To accomplish this communication, the events dispatched from the `EmailEventProcessor` class are 'posted' via the postMessage method and redispatched on the main thread. - A new `EmailEventStorage` class reacts to the email events and stores it in the database. This code mostly corresponds to the (now deleted) subclass of the old `EmailEventProcessor` - Updating a members last_seen_at timestamp has moved to the lastSeenAtUpdater. - Email events no longer store `ObjectID` because these are not encodable across threads via postMessage - Includes new E2E tests that test the storage of all supported Mailgun events. Note that in these tests we run the processing on the main thread instead of on a separate thread (couldn't do this because stubbing is not possible across threads) There are some missing pieces that will get added in later PRs (this PR focuses on porting the existing functionality): - Handling temporary failures/bounces - Capturing the error messages of bounce events
50 lines
851 B
JavaScript
50 lines
851 B
JavaScript
module.exports = class EmailDeliveredEvent {
|
|
/**
|
|
* @readonly
|
|
* @type {string}
|
|
*/
|
|
email;
|
|
|
|
/**
|
|
* @readonly
|
|
* @type {string}
|
|
*/
|
|
memberId;
|
|
|
|
/**
|
|
* @readonly
|
|
* @type {string}
|
|
*/
|
|
emailId;
|
|
|
|
/**
|
|
* @readonly
|
|
* @type {string}
|
|
*/
|
|
emailRecipientId;
|
|
|
|
/**
|
|
* @readonly
|
|
* @type {Date}
|
|
*/
|
|
timestamp;
|
|
|
|
/**
|
|
* @private
|
|
*/
|
|
constructor({email, memberId, emailId, emailRecipientId, timestamp}) {
|
|
this.email = email;
|
|
this.memberId = memberId;
|
|
this.emailId = emailId;
|
|
this.emailRecipientId = emailRecipientId;
|
|
this.timestamp = timestamp;
|
|
}
|
|
|
|
static create(data) {
|
|
return new EmailDeliveredEvent({
|
|
...data,
|
|
timestamp: data.timestamp || new Date
|
|
});
|
|
}
|
|
};
|