Skip to content

Commit

Permalink
fix(bullmq): add error handler
Browse files Browse the repository at this point in the history
make env var optional, add scoped gb instance
  • Loading branch information
kishore03109 committed Jun 21, 2024
1 parent 9d2f882 commit d6b5672
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 30 deletions.
6 changes: 0 additions & 6 deletions .aws/deploy/backend-task-definition.prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
"valueFrom": "PROD_INCOMING_QUEUE_URL"
},
{ "name": "JWT_SECRET", "valueFrom": "PROD_JWT_SECRET" },
{ "name": "KEYCDN_API_KEY", "valueFrom": "PROD_KEYCDN_API_KEY" },
{
"name": "MAX_NUM_OTP_ATTEMPTS",
"valueFrom": "PROD_MAX_NUM_OTP_ATTEMPTS"
Expand Down Expand Up @@ -133,11 +132,6 @@
"name": "REDIRECT_URI",
"valueFrom": "PROD_REDIRECT_URI"
},
{
"name": "REDIRECTION_REPO_GITHUB_TOKEN",
"valueFrom": "PROD_REDIRECTION_REPO_GITHUB_TOKEN"
},
{ "name": "REDIS_HOST", "valueFrom": "PROD_REDIS_HOST" },
{
"name": "SESSION_SECRET",
"valueFrom": "PROD_SESSION_SECRET"
Expand Down
6 changes: 0 additions & 6 deletions .aws/deploy/backend-task-definition.staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@
"valueFrom": "STAGING_INCOMING_QUEUE_URL"
},
{ "name": "JWT_SECRET", "valueFrom": "STAGING_JWT_SECRET" },
{ "name": "KEYCDN_API_KEY", "valueFrom": "STAGING_KEYCDN_API_KEY" },
{
"name": "MAX_NUM_OTP_ATTEMPTS",
"valueFrom": "STAGING_MAX_NUM_OTP_ATTEMPTS"
Expand Down Expand Up @@ -142,11 +141,6 @@
"name": "REDIRECT_URI",
"valueFrom": "STAGING_REDIRECT_URI"
},
{
"name": "REDIRECTION_REPO_GITHUB_TOKEN",
"valueFrom": "STAGING_REDIRECTION_REPO_GITHUB_TOKEN"
},
{ "name": "REDIS_HOST", "valueFrom": "STAGING_REDIS_HOST" },
{
"name": "SESSION_SECRET",
"valueFrom": "STAGING_SESSION_SECRET"
Expand Down
6 changes: 3 additions & 3 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ const config = convict({
redisHostname: {
doc: "Redis host name for bullmq",
env: "REDIS_HOST",
format: "required-string",
format: String,
default: "isomerpages",
},
},
Expand Down Expand Up @@ -258,7 +258,7 @@ const config = convict({
doc: "Github access to read opengovsg/isomer-redirection",
env: "REDIRECTION_REPO_GITHUB_TOKEN",
sensitive: true,
format: "required-string",
format: String,
default: "",
},
},
Expand Down Expand Up @@ -491,7 +491,7 @@ const config = convict({
apiKey: {
doc: "KeyCDN API key",
env: "KEYCDN_API_KEY",
format: "required-string",
format: String,
default: "",
},
},
Expand Down
16 changes: 14 additions & 2 deletions src/monitoring/MonitoringService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ export default class MonitoringService {
},
})

private readonly worker: Worker<unknown, string, string>
private readonly worker: Worker<
{
name: string
},
string,
string
>

private readonly monitoringWorker: MonitoringServiceInterface["monitoringWorker"]

Expand Down Expand Up @@ -96,9 +102,15 @@ export default class MonitoringService {
}
)

this.worker.on("error", (error: Error) => {
logger.error({
message: "Monitoring service has errored",
error,
})
})
this.worker.on("failed", (job: Job | undefined, error: Error) => {
logger.error({
message: "Monitoring service has failed",
message: "Monitoring service has errored",
error,
meta: {
...job?.data,
Expand Down
10 changes: 8 additions & 2 deletions src/monitoring/MonitoringWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import parentLogger from "@logger/logger"

import config from "@root/config/config"
import MonitoringError from "@root/errors/MonitoringError"
import { gb } from "@root/middleware/featureFlag"
import LaunchesService from "@root/services/identity/LaunchesService"
import { dnsMonitor } from "@root/utils/dns-utils"
import { getMonitoringConfig } from "@root/utils/growthbook-utils"
import {
getMonitoringConfig,
getNewGrowthbookInstance,
} from "@root/utils/growthbook-utils"
import promisifyPapaParse from "@root/utils/papa-parse"

const IsomerHostedDomainType = {
Expand Down Expand Up @@ -177,6 +179,10 @@ export default class MonitoringWorker {
}

driver() {
const gb = getNewGrowthbookInstance({
clientKey: config.get("growthbook.clientKey"),
subscribeToChanges: true,
})
const monitoringConfig = getMonitoringConfig(gb)
if (!monitoringConfig.isEnabled) {
this.monitoringWorkerLogger.info("Monitoring Service disabled")
Expand Down
17 changes: 9 additions & 8 deletions src/utils/dns-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import dns from "node:dns/promises"

import { err, errAsync, ok, okAsync, Result, ResultAsync } from "neverthrow"

import config from "@root/config/config"
import {
BUILT_WITH_ISOMER_LOGO,
DNS_CNAME_SUFFIXES,
Expand All @@ -11,9 +12,11 @@ import {
} from "@root/constants"
import MonitoringError from "@root/errors/MonitoringError"
import logger from "@root/logger/logger"
import { gb } from "@root/middleware/featureFlag"

import { getMonitoringConfig } from "./growthbook-utils"
import {
getMonitoringConfig,
getNewGrowthbookInstance,
} from "./growthbook-utils"

export function checkCname(domain: string) {
return ResultAsync.fromPromise(dns.resolveCname(domain), () => {
Expand All @@ -28,11 +31,6 @@ export function checkCname(domain: string) {
return okAsync(null)
}

//! todo: remove, this is some colima weird logic
if (cname.length === 1 && cname[0] === domain) {
return okAsync(null)
}

return okAsync(cname[0])
})
.orElse(() => okAsync(null))
Expand Down Expand Up @@ -305,7 +303,10 @@ export function dnsMonitor(domain: string): ResultAsync<string, string> {
`${domainCheckerRes}\nThe site is still being hosted with Isomer logo, and is likely still viewable by MOP`
)
}

const gb = getNewGrowthbookInstance({
clientKey: config.get("growthbook.clientKey"),
subscribeToChanges: true,
})
const monitoringConfig = getMonitoringConfig(gb)

const isWeirdDomain = monitoringConfig.whitelistedRepos.includes(
Expand Down
3 changes: 0 additions & 3 deletions support/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ infraService.pollMessages()
export const monitoringWorker = new MonitoringWorker({
launchesService,
})
// dnsMonitor("isomer.gov.sg").mapErr(console.log).map(console.log)
// todo: remove after testing
monitoringWorker.driver()

export const monitoringService = new MonitoringService({
monitoringWorker,
Expand Down

0 comments on commit d6b5672

Please sign in to comment.