diff --git a/docker-compose.yml b/docker-compose.yml index ae8b35048..ad805e272 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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-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 imex-carfax-uploads --create-bucket-configuration LocationConstraint=ca-central-1 " # Node App: The Main IMEX API node-app: diff --git a/hasura/metadata/cron_triggers.yaml b/hasura/metadata/cron_triggers.yaml index 534560869..cc1baa225 100644 --- a/hasura/metadata/cron_triggers.yaml +++ b/hasura/metadata/cron_triggers.yaml @@ -6,6 +6,15 @@ headers: - name: x-imex-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 webhook: '{{HASURA_API_URL}}/data/chatter' schedule: 45 5 * * * diff --git a/server/data/carfax.js b/server/data/carfax.js index b25e371a8..c1db22193 100644 --- a/server/data/carfax.js +++ b/server/data/carfax.js @@ -6,7 +6,7 @@ const InstanceManager = require("../utils/instanceMgr").default; const { isString, isEmpty } = require("lodash"); const fs = require("fs"); 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 crypto = require("crypto"); @@ -168,6 +168,29 @@ async function processShopData(shopsToProcess, start, end, skipUpload, ignoreDat 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({ bodyshopid: bodyshop.id, imexshopid: shopid, @@ -402,3 +425,14 @@ const generatePartType = (type) => { 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; +}; diff --git a/server/email/sendemail.js b/server/email/sendemail.js index 6622cb6ce..c9a72c17f 100644 --- a/server/email/sendemail.js +++ b/server/email/sendemail.js @@ -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} `, + rome: `Rome Online API - ${process.env.NODE_ENV} ` + }), + 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 }) => { try { await mailer.sendMail({ @@ -420,6 +455,7 @@ ${body.bounce?.bouncedRecipients.map( module.exports = { sendEmail, sendServerEmail, + sendMexicoBillingEmail, sendTaskEmail, emailBounce, sendWelcomeEmail