Set url for sent emails

This commit is contained in:
Manuel Romero
2020-10-22 15:39:21 +02:00
parent 7516f46903
commit b3895be44a
4 changed files with 23 additions and 29 deletions

View File

@@ -95,6 +95,7 @@ services:
container_name: qmi-cloud-worker
restart: on-failure
environment:
- HOSTNAME_URL=http://localhost:3000
- REDIS_URL=redis://redis
- MONGO_URI=mongodb://root:example@mongo/qmicloud?authSource=admin
- PROJECT_PATH=%PWD%

View File

@@ -3,6 +3,11 @@ const nodemailer = require('nodemailer');
const FROM = '"Qlik" <no-reply@qlik.com>';
var transporter;
const HOSTNAME_URL = process.env.HOSTNAME_URL || "https://qmicloud.qliktech.com";
const FOOTER = `<div style="color:#404040;font-size:16px;margin:30px 0px">
<p style="margin:0px">Check it out at <a href="${HOSTNAME_URL}">${HOSTNAME_URL}</a></p>
</div>`;
if ( process.env.GMAIL_USERNAME && process.env.GMAIL_PASSWORD ) {
//GMAIL
transporter = nodemailer.createTransport({
@@ -85,9 +90,7 @@ function getHtmlScenarioDestroyIn24( provision, scenario, period, warningDays) {
<p style="margin:0px">If you don't want this to happen, you've got ${(warningDays*24)} hours (from when this email was sent) as a grace period to get back at 'Running' status this provision.</p>
</div>
${common}
<div style="color:#404040;font-size:16px;margin:30px 0px">
<p style="margin:0px">Check it out at <a href="https://qmicloud.qliktech.com">https://qmicloud.qliktech.com</a></p>
</div>
${FOOTER}
</div>
</div>`;
}
@@ -107,12 +110,10 @@ function getHtmlScenarioVMsStopped( provision, scenario) {
<p style="margin:0px;color: #FF2020">All VMs for this provision <b>stopped</b> automatically.</p>
</div>
<div style="color:#404040;font-size:16px;margin:30px 0px">
<p style="margin:0px">You can start them up again from <a href="https://qmicloud.qliktech.com">https://qmicloud.qliktech.com</a></p>
<p style="margin:0px">You can start them up again from <a href="${HOSTNAME_URL}">${HOSTNAME_URL}</a></p>
</div>
${common}
<div style="color:#404040;font-size:16px;margin:30px 0px">
<p style="margin:0px">Check it out at <a href="https://qmicloud.qliktech.com">https://qmicloud.qliktech.com</a></p>
</div>
${FOOTER}
</div>
</div>`;
}
@@ -137,9 +138,7 @@ function getHtmlScenarioWillStopIn24( provision, scenario, period, warningDays )
<p style="margin:0px">If you don't want the VMs to automatically stop, you've got ${warningDays*24} hours (from when this email was sent) as a grace period to extend this scenario's <b style="color: #009845">Running</b> VMs for ${(period+warningDays)} extra days.</p>
</div>
${common}
<div style="color:#404040;font-size:16px;margin:30px 0px">
<p style="margin:0px">Check it out at <a href="https://qmicloud.qliktech.com">https://qmicloud.qliktech.com</a></p>
</div>
${FOOTER}
</div>
</div>`;
}
@@ -173,9 +172,7 @@ function getHtmlNewProvision(provision, scenario) {
<div style="margin: 30px 0px;">
${htmlint}
</div>
<div style="color:#404040;font-size:16px;margin:30px 0px">
<p style="margin:0px">Check it out at <a href="https://qmicloud.qliktech.com">https://qmicloud.qliktech.com</a></p>
</div>
${FOOTER}
</div>
</div>`;
@@ -195,9 +192,7 @@ function getHtmlErrorProvision(provision, scenario) {
<p style="margin:0px">Scenario '${scenario.title}' failed during provision.</p>
</div>
${common}
<div style="color:#404040;font-size:16px;margin:30px 0px">
<p style="margin:0px">Check it out at <a href="https://qmicloud.qliktech.com">https://qmicloud.qliktech.com</a></p>
</div>
${FOOTER}
</div>
</div>`;
}
@@ -213,26 +208,24 @@ function getHtmlDestroyProvision(provision, scenario) {
<p style="margin:0px">Scenario '${scenario.title}' successfully destroyed!</p>
</div>
${common}
<div style="color:#404040;font-size:16px;margin:30px 0px">
<p style="margin:0px">Check it out at <a href="https://qmicloud.qliktech.com">https://qmicloud.qliktech.com</a></p>
</div>
${FOOTER}
</div>
</div>`;
}
// async..await is not allowed in global scope, must use a wrapper
async function send( provision, scenario ) {
async function sendProvisionSuccess( provision, scenario ) {
const htmlText = getHtmlNewProvision(provision, scenario);
await _doSend(provision.user.upn, 'QMI Cloud - Provision finished successfully', htmlText);
}
async function sendError(provision, scenario ) {
async function sendProvisionError(provision, scenario ) {
const htmlText = getHtmlErrorProvision(provision, scenario);
await _doSend(provision.user.upn, 'QMI Cloud - Provision with failures', htmlText);
}
async function sendDestroyed(provision, scenario ) {
async function sendDestroyedSuccess(provision, scenario ) {
const htmlText = getHtmlDestroyProvision(provision, scenario);
await _doSend(provision.user.upn, 'QMI Cloud - Provision destroyed successfully', htmlText);
@@ -257,9 +250,9 @@ async function sendVMsStopped( provision, scenario ) {
await _doSend(provision.user.upn, 'QMI Cloud - VMs stopped automatically', htmlText);
}
module.exports.send = send;
module.exports.sendError = sendError;
module.exports.sendDestroyed = sendDestroyed;
module.exports.sendProvisionSuccess = sendProvisionSuccess;
module.exports.sendProvisionError = sendProvisionError;
module.exports.sendDestroyedSuccess = sendDestroyedSuccess;
module.exports.sendWillStopIn24 = sendWillStopIn24;
module.exports.sendVMsStopped = sendVMsStopped;
module.exports.sendWillDestroyIn24 = sendWillDestroyIn24;

View File

@@ -60,15 +60,15 @@ module.exports = async function(job) {
return azure.createimage(prov, job.data._scenario);
} ).then( function(prov) {
if (prov.status === "provisioned") {
sendEmail.send(prov, job.data._scenario);
sendEmail.sendProvisionSuccess(prov, job.data._scenario);
} else {
sendEmail.sendError(prov, job.data._scenario);
sendEmail.sendProvisionError(prov, job.data._scenario);
}
return Promise.resolve({"success": true, provMongo: prov});
} ).catch( function(err) {
console.log("ProcessorApply# Provision: error", err);
db.provision.update(prov._id, {"status": err.provStatus? err.provStatus : 'error'});
sendEmail.sendError(prov, job.data._scenario);
sendEmail.sendProvisionError(prov, job.data._scenario);
return Promise.reject({"success": false, "error": err});
} );
}

View File

@@ -28,7 +28,7 @@ module.exports = async function(job){
update = await db.destroy.update(destroyMongo._id, {"status": "destroyed"});
let timeRunning = db.utils.getNewTimeRunning(provMongo);
update2 = await db.provision.update(provMongo._id, {"isDestroyed": true, "timeRunning": timeRunning, "pendingNextAction": undefined, "actualDestroyDate": new Date()});
sendEmail.sendDestroyed(update2, job.data._scenario);
sendEmail.sendDestroyedSuccess(update2, job.data._scenario);
}
return { destroy: update, provision: update2 };
}).then(async function(res) {