Skip to content

Commit

Permalink
Set environment, updated packages, etc
Browse files Browse the repository at this point in the history
  • Loading branch information
dhochbaum-dcp committed Oct 29, 2024
1 parent 05d0be5 commit d797606
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 64 deletions.
1 change: 0 additions & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions server/src/sentry/instrument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { nodeProfilingIntegration } from '@sentry/profiling-node';
// Ensure to call this before importing any other modules!
Sentry.init({
dsn: "https://[email protected]/6410746",
environment: process.env.NODE_ENV === "production" ? "production" : "staging",
integrations: [
// Add our Profiling integration
nodeProfilingIntegration(),
Expand Down
4 changes: 2 additions & 2 deletions server/src/subscriber/subscriber.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
30 changes: 20 additions & 10 deletions server/src/subscriber/subscriber.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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,
Expand All @@ -113,20 +122,21 @@ export class SubscriberService {

const confirmationRequest = {
url: `/v3/marketing/contacts/imports/${importId}`,
// method:<HttpMethod> 'GET',
method:<HttpMethod> '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);
Expand Down
51 changes: 0 additions & 51 deletions server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1272,44 +1272,6 @@
dependencies:
deepmerge "^4.2.2"

"@sentry-internal/[email protected]":
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/[email protected]":
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/[email protected]":
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/[email protected]":
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/[email protected]":
version "7.119.2"
resolved "https://registry.yarnpkg.com/@sentry-internal/tracing/-/tracing-7.119.2.tgz#f1f09e0fd727b00366f4ac24a5b427c1ed117a1a"
Expand All @@ -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"
Expand Down

0 comments on commit d797606

Please sign in to comment.