mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-05 21:12:52 +00:00
refactor: move repetitive code into a new method in mailQueue
This commit is contained in:
committed by
Rainer Killinger
parent
af305aa196
commit
dd6ea1c6f3
@@ -67,18 +67,27 @@ export class MailQueue {
|
|||||||
this.checkForVerification();
|
this.checkForVerification();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a mail into the queue so it gets send when the queue is ready
|
||||||
|
*
|
||||||
|
* @param mail Information required for sending a mail
|
||||||
|
*/
|
||||||
|
private async addToQueue(mail: MailOptions) {
|
||||||
|
return this.queue.add<string>(() => this.transport.sendMail(mail));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Verify the given transport
|
* Verify the given transport
|
||||||
*/
|
*/
|
||||||
private checkForVerification() {
|
private checkForVerification() {
|
||||||
|
|
||||||
if (this.verificationCounter > MailQueue.MAX_VERIFICATION_ATTEMPTS) {
|
if (this.verificationCounter >= MailQueue.MAX_VERIFICATION_ATTEMPTS) {
|
||||||
throw new Error('Failed to initialize the SMTP transport for the mail queue');
|
throw new Error('Failed to initialize the SMTP transport for the mail queue');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.transport.isVerified()) {
|
if (!this.transport.isVerified()) {
|
||||||
this.verificationCounter++;
|
this.verificationCounter++;
|
||||||
setTimeout(async () => {
|
setTimeout(() => {
|
||||||
Logger.warn('Transport not verified yet. Trying to send mails here...');
|
Logger.warn('Transport not verified yet. Trying to send mails here...');
|
||||||
this.checkForVerification();
|
this.checkForVerification();
|
||||||
}, MailQueue.VERIFICATION_TIMEOUT);
|
}, MailQueue.VERIFICATION_TIMEOUT);
|
||||||
@@ -86,7 +95,7 @@ export class MailQueue {
|
|||||||
Logger.ok('Transport for mail queue was verified. We can send mails now');
|
Logger.ok('Transport for mail queue was verified. We can send mails now');
|
||||||
// if the transport finally was verified send all our mails from the dry queue
|
// if the transport finally was verified send all our mails from the dry queue
|
||||||
this.dryQueue.forEach(async (mail) => {
|
this.dryQueue.forEach(async (mail) => {
|
||||||
await this.queue.add<string>(() => (this.transport as SMTP).sendMail(mail));
|
await this.addToQueue(mail);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -101,7 +110,7 @@ export class MailQueue {
|
|||||||
// push to a dry queue which gets pushed to the real queue when the transport is verified
|
// push to a dry queue which gets pushed to the real queue when the transport is verified
|
||||||
this.dryQueue.push(mail);
|
this.dryQueue.push(mail);
|
||||||
} else {
|
} else {
|
||||||
await this.queue.add<string>(() => (this.transport as SMTP).sendMail(mail));
|
await this.addToQueue(mail);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user