Fix, pgboss connection issue
This commit is contained in:
@@ -46,6 +46,7 @@ export const env = createEnv({
|
||||
.default(2),
|
||||
FROM_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,
|
||||
NEXT_PUBLIC_IS_CLOUD: process.env.NEXT_PUBLIC_IS_CLOUD,
|
||||
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
|
||||
|
@@ -7,6 +7,7 @@ import {
|
||||
sendEmailWithAttachments,
|
||||
} from "~/server/aws/ses";
|
||||
import { getConfigurationSetName } from "~/utils/ses-utils";
|
||||
import { sendToDiscord } from "./notification-service";
|
||||
|
||||
const boss = new pgBoss({
|
||||
connectionString: env.DATABASE_URL,
|
||||
@@ -27,6 +28,15 @@ export async function getBoss() {
|
||||
},
|
||||
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;
|
||||
}
|
||||
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