From d7976066a6e5a2811a01bc177a4b64ea2f05ee7e Mon Sep 17 00:00:00 2001 From: David Hochbaum Date: Tue, 29 Oct 2024 14:48:08 -0400 Subject: [PATCH] Set environment, updated packages, etc --- server/package.json | 1 - server/src/sentry/instrument.ts | 1 + .../src/subscriber/subscriber.controller.ts | 4 +- server/src/subscriber/subscriber.service.ts | 30 +++++++---- server/yarn.lock | 51 ------------------- 5 files changed, 23 insertions(+), 64 deletions(-) diff --git a/server/package.json b/server/package.json index b7c1d91f..306e60f0 100644 --- a/server/package.json +++ b/server/package.json @@ -36,7 +36,6 @@ "@nestjs/testing": "^8.4.7", "@octokit/rest": "^16.43.1", "@sendgrid/client": "^8.1.3", - "@sentry/browser": "^8.35.0", "@sentry/nestjs": "^8.35.0", "@sentry/profiling-node": "^8.35.0", "@sentry/wizard": "^3.34.2", diff --git a/server/src/sentry/instrument.ts b/server/src/sentry/instrument.ts index a6b8c5dd..94b72fed 100644 --- a/server/src/sentry/instrument.ts +++ b/server/src/sentry/instrument.ts @@ -4,6 +4,7 @@ import { nodeProfilingIntegration } from '@sentry/profiling-node'; // Ensure to call this before importing any other modules! Sentry.init({ dsn: "https://cb886cd8649348e3b402c8fd36ab30bc@o1081909.ingest.us.sentry.io/6410746", + environment: process.env.NODE_ENV === "production" ? "production" : "staging", integrations: [ // Add our Profiling integration nodeProfilingIntegration(), diff --git a/server/src/subscriber/subscriber.controller.ts b/server/src/subscriber/subscriber.controller.ts index 182abcf1..bdfa3e05 100644 --- a/server/src/subscriber/subscriber.controller.ts +++ b/server/src/subscriber/subscriber.controller.ts @@ -3,7 +3,7 @@ import { ConfigService } from "../config/config.service"; import { SubscriberService } from "./subscriber.service"; import { Request } from "express"; import validateEmail from "../_utils/validate-email"; -import * as Sentry from "@sentry/browser"; +import * as Sentry from "@sentry/nestjs"; const PAUSE_BETWEEN_CHECKS = 30000; const CHECKS_BEFORE_FAIL = 10; @@ -77,7 +77,7 @@ export class SubscriberController { } // Now we keep checking to make sure the import was successful - const importConfirmation = await this.subscriberService.checkCreate(addToQueue.result[1]["job_id"], response, 0, CHECKS_BEFORE_FAIL, PAUSE_BETWEEN_CHECKS, this.list, errorInfo); + const importConfirmation = await this.subscriberService.checkCreate(addToQueue.result[1]["job_id"], response, 0, CHECKS_BEFORE_FAIL, PAUSE_BETWEEN_CHECKS, errorInfo); return; diff --git a/server/src/subscriber/subscriber.service.ts b/server/src/subscriber/subscriber.service.ts index e5dd5a76..9e0c9f27 100644 --- a/server/src/subscriber/subscriber.service.ts +++ b/server/src/subscriber/subscriber.service.ts @@ -2,7 +2,7 @@ import { Injectable, Res } from "@nestjs/common"; import { ConfigService } from "../config/config.service"; import { Client } from "@sendgrid/client"; import crypto from 'crypto'; -import * as Sentry from "@sentry/browser"; +import * as Sentry from "@sentry/nestjs"; const validCustomFieldNames = ["K01", "K02", "K03", "K04", "K05", "K06", "K07", "K08", "K09", "K10", "K11", "K12", "K13", "K14", "K15", "K16", "K17", "K18", "X01", "X02", "X03", "X04", "X05", "X06", "X07", "X08", "X09", "X10", "X11", "X12", "M01", "M02", "M03", "M04", "M05", "M06", "M07", "M08", "M09", "M10", "M11", "M12", "Q01", "Q02", "Q03", "Q04", "Q05", "Q06", "Q07", "Q08", "Q09", "Q10", "Q11", "Q12", "Q13", "Q14", "R01", "R02", "R03", "CW"] as const; export type CustomFieldNameTuple = typeof validCustomFieldNames; type CustomFieldName = CustomFieldNameTuple[number]; @@ -92,7 +92,16 @@ export class SubscriberService { } } - async checkCreate(importId: string, @Res() response, counter: number = 0, checksBeforeFail: number, pauseBetweenChecks: number, list: string, errorInfo: any) { + /** + * Checks that a job has imported correctly. + * @param {string} importId - The job id returned by the initial request + * @param {number} counter - Tracks the number of times we have checked + * @param {number} checksBeforeFail - Max # times to check + * @param {number} pauseBetweenChecks - How long to wait between checks, in milliseconds + * @param {object} errorInfo - Additional info to log in case of error + * @returns {object} + */ + async checkCreate(importId: string, @Res() response, counter: number = 0, checksBeforeFail: number, pauseBetweenChecks: number, errorInfo: any) { if(counter >= checksBeforeFail) { console.error({ code: 408, @@ -113,20 +122,21 @@ export class SubscriberService { const confirmationRequest = { url: `/v3/marketing/contacts/imports/${importId}`, + // method: 'GET', method: 'GET', } // https://www.twilio.com/docs/sendgrid/api-reference/contacts/import-contacts-status try { - const user = await this.client.request(confirmationRequest); - if(user[1].status === "pending") { - return await this.checkCreate(importId, response, counter + 1, checksBeforeFail, pauseBetweenChecks, list, errorInfo); - } else if (["errored", "failed"].includes(user[1].status)) { - console.error(user, errorInfo); - Sentry.captureException(user, errorInfo); - return {isError: true, user, errorInfo}; + const job = await this.client.request(confirmationRequest); + if(job[1].status === "pending") { + return await this.checkCreate(importId, response, counter + 1, checksBeforeFail, pauseBetweenChecks, errorInfo); + } else if (["errored", "failed"].includes(job[1].status)) { + console.error(job, errorInfo); + Sentry.captureException(job, errorInfo); + return {isError: true, job, errorInfo}; } - return {isError: false, status: user[1].status, ...user}; + return {isError: false, status: job[1].status, ...job}; } catch(error) { console.error(error, errorInfo); Sentry.captureException(error, errorInfo); diff --git a/server/yarn.lock b/server/yarn.lock index 27403301..e05d889e 100644 --- a/server/yarn.lock +++ b/server/yarn.lock @@ -1272,44 +1272,6 @@ dependencies: deepmerge "^4.2.2" -"@sentry-internal/browser-utils@8.35.0": - version "8.35.0" - resolved "https://registry.yarnpkg.com/@sentry-internal/browser-utils/-/browser-utils-8.35.0.tgz#92602f8dd2bb777af2994eb446cb3cf71bf0cfad" - integrity sha512-uj9nwERm7HIS13f/Q52hF/NUS5Al8Ma6jkgpfYGeppYvU0uSjPkwMogtqoJQNbOoZg973tV8qUScbcWY616wNA== - dependencies: - "@sentry/core" "8.35.0" - "@sentry/types" "8.35.0" - "@sentry/utils" "8.35.0" - -"@sentry-internal/feedback@8.35.0": - version "8.35.0" - resolved "https://registry.yarnpkg.com/@sentry-internal/feedback/-/feedback-8.35.0.tgz#b31fb7fbec8ecd9cc683948a0d1af2b87731b0a1" - integrity sha512-7bjSaUhL0bDArozre6EiIhhdWdT/1AWNWBC1Wc5w1IxEi5xF7nvF/FfvjQYrONQzZAI3HRxc45J2qhLUzHBmoQ== - dependencies: - "@sentry/core" "8.35.0" - "@sentry/types" "8.35.0" - "@sentry/utils" "8.35.0" - -"@sentry-internal/replay-canvas@8.35.0": - version "8.35.0" - resolved "https://registry.yarnpkg.com/@sentry-internal/replay-canvas/-/replay-canvas-8.35.0.tgz#de7849e0d4212ee37a9225b1fc346188d9b05072" - integrity sha512-TUrH6Piv19kvHIiRyIuapLdnuwxk/Un/l1WDCQfq7mK9p1Pac0FkQ7Uufjp6zY3lyhDDZQ8qvCS4ioCMibCwQg== - dependencies: - "@sentry-internal/replay" "8.35.0" - "@sentry/core" "8.35.0" - "@sentry/types" "8.35.0" - "@sentry/utils" "8.35.0" - -"@sentry-internal/replay@8.35.0": - version "8.35.0" - resolved "https://registry.yarnpkg.com/@sentry-internal/replay/-/replay-8.35.0.tgz#f71abae95cb492a54b43885386adbc5c639486c7" - integrity sha512-3wkW03vXYMyWtTLxl9yrtkV+qxbnKFgfASdoGWhXzfLjycgT6o4/04eb3Gn71q9aXqRwH17ISVQbVswnRqMcmA== - dependencies: - "@sentry-internal/browser-utils" "8.35.0" - "@sentry/core" "8.35.0" - "@sentry/types" "8.35.0" - "@sentry/utils" "8.35.0" - "@sentry-internal/tracing@7.119.2": version "7.119.2" resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.119.2.tgz#f1f09e0fd727b00366f4ac24a5b427c1ed117a1a" @@ -1319,19 +1281,6 @@ "@sentry/types" "7.119.2" "@sentry/utils" "7.119.2" -"@sentry/browser@^8.35.0": - version "8.35.0" - resolved "https://registry.yarnpkg.com/@sentry/browser/-/browser-8.35.0.tgz#67820951fd092ef72ee1a4897464bc7c8d317d77" - integrity sha512-WHfI+NoZzpCsmIvtr6ChOe7yWPLQyMchPnVhY3Z4UeC70bkYNdKcoj/4XZbX3m0D8+71JAsm0mJ9s9OC3Ue6MQ== - dependencies: - "@sentry-internal/browser-utils" "8.35.0" - "@sentry-internal/feedback" "8.35.0" - "@sentry-internal/replay" "8.35.0" - "@sentry-internal/replay-canvas" "8.35.0" - "@sentry/core" "8.35.0" - "@sentry/types" "8.35.0" - "@sentry/utils" "8.35.0" - "@sentry/cli@^1.72.0": version "1.77.3" resolved "https://registry.yarnpkg.com/@sentry/cli/-/cli-1.77.3.tgz#c40b4d09b0878d6565d42a915855add99db4fec3"