Fix, pgboss connection issue
This commit is contained in:
@@ -46,6 +46,7 @@ export const env = createEnv({
|
|||||||
.default(2),
|
.default(2),
|
||||||
FROM_EMAIL: z.string().optional(),
|
FROM_EMAIL: z.string().optional(),
|
||||||
ADMIN_EMAIL: z.string().optional(),
|
ADMIN_EMAIL: z.string().optional(),
|
||||||
|
DISCORD_WEBHOOK_URL: z.string().optional(),
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -82,6 +83,7 @@ export const env = createEnv({
|
|||||||
API_RATE_LIMIT: process.env.API_RATE_LIMIT,
|
API_RATE_LIMIT: process.env.API_RATE_LIMIT,
|
||||||
NEXT_PUBLIC_IS_CLOUD: process.env.NEXT_PUBLIC_IS_CLOUD,
|
NEXT_PUBLIC_IS_CLOUD: process.env.NEXT_PUBLIC_IS_CLOUD,
|
||||||
ADMIN_EMAIL: process.env.ADMIN_EMAIL,
|
ADMIN_EMAIL: process.env.ADMIN_EMAIL,
|
||||||
|
DISCORD_WEBHOOK_URL: process.env.DISCORD_WEBHOOK_URL,
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
|
* Run `build` or `dev` with `SKIP_ENV_VALIDATION` to skip env validation. This is especially
|
||||||
|
@@ -7,6 +7,7 @@ import {
|
|||||||
sendEmailWithAttachments,
|
sendEmailWithAttachments,
|
||||||
} from "~/server/aws/ses";
|
} from "~/server/aws/ses";
|
||||||
import { getConfigurationSetName } from "~/utils/ses-utils";
|
import { getConfigurationSetName } from "~/utils/ses-utils";
|
||||||
|
import { sendToDiscord } from "./notification-service";
|
||||||
|
|
||||||
const boss = new pgBoss({
|
const boss = new pgBoss({
|
||||||
connectionString: env.DATABASE_URL,
|
connectionString: env.DATABASE_URL,
|
||||||
@@ -27,6 +28,15 @@ export async function getBoss() {
|
|||||||
},
|
},
|
||||||
executeEmail
|
executeEmail
|
||||||
);
|
);
|
||||||
|
|
||||||
|
boss.on("error", async (error) => {
|
||||||
|
console.error(error);
|
||||||
|
sendToDiscord(
|
||||||
|
`Error in pg-boss: ${error.name} \n ${error.cause}\n ${error.message}\n ${error.stack}`
|
||||||
|
);
|
||||||
|
await boss.stop();
|
||||||
|
started = false;
|
||||||
|
});
|
||||||
started = true;
|
started = true;
|
||||||
}
|
}
|
||||||
return boss;
|
return boss;
|
||||||
|
28
apps/web/src/server/service/notification-service.ts
Normal file
28
apps/web/src/server/service/notification-service.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import { env } from "~/env";
|
||||||
|
|
||||||
|
export async function sendToDiscord(message: string) {
|
||||||
|
if (!env.DISCORD_WEBHOOK_URL) {
|
||||||
|
console.error(
|
||||||
|
"Discord webhook URL is not defined in the environment variables. So printing the message to the console."
|
||||||
|
);
|
||||||
|
console.log("Message: ", message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const webhookUrl = env.DISCORD_WEBHOOK_URL;
|
||||||
|
const response = await fetch(webhookUrl, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ content: message }),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
console.log("Message sent to Discord successfully.");
|
||||||
|
} else {
|
||||||
|
console.error("Failed to send message to Discord:", response.statusText);
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
Reference in New Issue
Block a user