IO-3330 CARFAX Datapump Adjustment
Cron trigger and billing email Signed-off-by: Allan Carr <allan@imexsystems.ca>
This commit is contained in:
@@ -119,6 +119,7 @@ services:
|
|||||||
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket imex-large-log --create-bucket-configuration LocationConstraint=ca-central-1
|
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket imex-large-log --create-bucket-configuration LocationConstraint=ca-central-1
|
||||||
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket imex-job-totals --create-bucket-configuration LocationConstraint=ca-central-1
|
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket imex-job-totals --create-bucket-configuration LocationConstraint=ca-central-1
|
||||||
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket parts-estimates --create-bucket-configuration LocationConstraint=ca-central-1
|
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket parts-estimates --create-bucket-configuration LocationConstraint=ca-central-1
|
||||||
|
aws --endpoint-url=http://localstack:4566 s3api create-bucket --bucket imex-carfax-uploads --create-bucket-configuration LocationConstraint=ca-central-1
|
||||||
"
|
"
|
||||||
# Node App: The Main IMEX API
|
# Node App: The Main IMEX API
|
||||||
node-app:
|
node-app:
|
||||||
|
|||||||
@@ -6,6 +6,15 @@
|
|||||||
headers:
|
headers:
|
||||||
- name: x-imex-auth
|
- name: x-imex-auth
|
||||||
value_from_env: DATAPUMP_AUTH
|
value_from_env: DATAPUMP_AUTH
|
||||||
|
- name: CARFAX Data Pump
|
||||||
|
webhook: '{{HASURA_API_URL}}/data/carfax'
|
||||||
|
schedule: 0 7 * * 6
|
||||||
|
include_in_metadata: true
|
||||||
|
payload: {}
|
||||||
|
headers:
|
||||||
|
- name: x-imex-auth
|
||||||
|
value_from_env: DATAPUMP_AUTH
|
||||||
|
comment: Project Mexico
|
||||||
- name: Chatter Data Pump
|
- name: Chatter Data Pump
|
||||||
webhook: '{{HASURA_API_URL}}/data/chatter'
|
webhook: '{{HASURA_API_URL}}/data/chatter'
|
||||||
schedule: 45 5 * * *
|
schedule: 45 5 * * *
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const InstanceManager = require("../utils/instanceMgr").default;
|
|||||||
const { isString, isEmpty } = require("lodash");
|
const { isString, isEmpty } = require("lodash");
|
||||||
const fs = require("fs");
|
const fs = require("fs");
|
||||||
const client = require("../graphql-client/graphql-client").client;
|
const client = require("../graphql-client/graphql-client").client;
|
||||||
const { sendServerEmail } = require("../email/sendemail");
|
const { sendServerEmail, sendMexicoBillingEmail } = require("../email/sendemail");
|
||||||
const { uploadFileToS3 } = require("../utils/s3");
|
const { uploadFileToS3 } = require("../utils/s3");
|
||||||
const crypto = require("crypto");
|
const crypto = require("crypto");
|
||||||
|
|
||||||
@@ -168,6 +168,29 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat
|
|||||||
await uploadViaSFTP(jsonObj);
|
await uploadViaSFTP(jsonObj);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await sendMexicoBillingEmail({
|
||||||
|
subject: `${shopid.toUpperCase()}_Mexico_${moment().format("MM-DD-YY")} ROs ${jsonObj.count} Error ${errorCode(jsonObj)}`,
|
||||||
|
text: `Errors:\n${JSON.stringify(
|
||||||
|
erroredJobs.map((ej) => ({
|
||||||
|
ro_number: ej.job?.ro_number,
|
||||||
|
jobid: ej.job?.id,
|
||||||
|
error: ej.error
|
||||||
|
})),
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
)}\n\nUploaded:\n${JSON.stringify(
|
||||||
|
{
|
||||||
|
bodyshopid: bodyshop.id,
|
||||||
|
imexshopid: shopid,
|
||||||
|
count: jsonObj.count,
|
||||||
|
filename: jsonObj.filename,
|
||||||
|
result: jsonObj.result
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
)}`
|
||||||
|
});
|
||||||
|
|
||||||
allXMLResults.push({
|
allXMLResults.push({
|
||||||
bodyshopid: bodyshop.id,
|
bodyshopid: bodyshop.id,
|
||||||
imexshopid: shopid,
|
imexshopid: shopid,
|
||||||
@@ -402,3 +425,14 @@ const generatePartType = (type) => {
|
|||||||
|
|
||||||
return partTypeMap[type?.toLowerCase()] || null;
|
return partTypeMap[type?.toLowerCase()] || null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const errorCode = ({ count, filename, results }) => {
|
||||||
|
if (count === 0) return 1;
|
||||||
|
if (!filename) return 3;
|
||||||
|
const sftpErrorCode = results?.sftpError?.code;
|
||||||
|
if (sftpErrorCode && ["ECONNREFUSED", "ENOTFOUND", "ETIMEDOUT", "ECONNRESET"].includes(sftpErrorCode)) {
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
if (sftpErrorCode) return 7;
|
||||||
|
return 0;
|
||||||
|
};
|
||||||
|
|||||||
@@ -79,6 +79,41 @@ const sendServerEmail = async ({ subject, text }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const sendMexicoBillingEmail = async ({ subject, text }) => {
|
||||||
|
if (process.env.NODE_ENV === undefined) return;
|
||||||
|
try {
|
||||||
|
mailer.sendMail(
|
||||||
|
{
|
||||||
|
from: InstanceManager({
|
||||||
|
imex: `ImEX Online API - ${process.env.NODE_ENV} <noreply@imex.online>`,
|
||||||
|
rome: `Rome Online API - ${process.env.NODE_ENV} <noreply@romeonline.io>`
|
||||||
|
}),
|
||||||
|
to: ["mexico@rometech.zohodesk.com"],
|
||||||
|
subject: subject,
|
||||||
|
text: text,
|
||||||
|
ses: {
|
||||||
|
// optional extra arguments for SendRawEmail
|
||||||
|
Tags: [
|
||||||
|
{
|
||||||
|
Name: "tag_name",
|
||||||
|
Value: "tag_value"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
(err, info) => {
|
||||||
|
logger.log("server-email-failure", err ? "error" : "debug", null, null, {
|
||||||
|
message: err?.message,
|
||||||
|
stack: err?.stack
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
logger.log("server-email-failure", "error", null, null, { message: error?.message, stack: error?.stack });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const sendWelcomeEmail = async ({ to, resetLink, dateLine, features, bcc }) => {
|
const sendWelcomeEmail = async ({ to, resetLink, dateLine, features, bcc }) => {
|
||||||
try {
|
try {
|
||||||
await mailer.sendMail({
|
await mailer.sendMail({
|
||||||
@@ -420,6 +455,7 @@ ${body.bounce?.bouncedRecipients.map(
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
sendEmail,
|
sendEmail,
|
||||||
sendServerEmail,
|
sendServerEmail,
|
||||||
|
sendMexicoBillingEmail,
|
||||||
sendTaskEmail,
|
sendTaskEmail,
|
||||||
emailBounce,
|
emailBounce,
|
||||||
sendWelcomeEmail
|
sendWelcomeEmail
|
||||||
|
|||||||
Reference in New Issue
Block a user