fix(dokploy): filter notifications by admin

This commit is contained in:
Mauricio Siu
2024-11-04 10:10:52 -06:00
parent 8af5afbb6c
commit 6b7712e35f
11 changed files with 45 additions and 10 deletions

View File

@@ -242,7 +242,7 @@ export const settingsRouter = createTRPCRouter({
await cleanUpUnusedImages(server.serverId); await cleanUpUnusedImages(server.serverId);
await cleanUpDockerBuilder(server.serverId); await cleanUpDockerBuilder(server.serverId);
await cleanUpSystemPrune(server.serverId); await cleanUpSystemPrune(server.serverId);
await sendDockerCleanupNotifications(); await sendDockerCleanupNotifications(server.adminId);
}); });
} }
} else { } else {
@@ -278,7 +278,7 @@ export const settingsRouter = createTRPCRouter({
await cleanUpUnusedImages(); await cleanUpUnusedImages();
await cleanUpDockerBuilder(); await cleanUpDockerBuilder();
await cleanUpSystemPrune(); await cleanUpSystemPrune();
await sendDockerCleanupNotifications(); await sendDockerCleanupNotifications(admin.adminId);
}); });
} else { } else {
const currentJob = scheduledJobs["docker-cleanup"]; const currentJob = scheduledJobs["docker-cleanup"];

View File

@@ -193,6 +193,7 @@ export const deployApplication = async ({
applicationName: application.name, applicationName: application.name,
applicationType: "application", applicationType: "application",
buildLink, buildLink,
adminId: application.project.adminId,
}); });
} catch (error) { } catch (error) {
await updateDeploymentStatus(deployment.deploymentId, "error"); await updateDeploymentStatus(deployment.deploymentId, "error");
@@ -204,6 +205,7 @@ export const deployApplication = async ({
// @ts-ignore // @ts-ignore
errorMessage: error?.message || "Error to build", errorMessage: error?.message || "Error to build",
buildLink, buildLink,
adminId: application.project.adminId,
}); });
console.log( console.log(
@@ -314,6 +316,7 @@ export const deployRemoteApplication = async ({
applicationName: application.name, applicationName: application.name,
applicationType: "application", applicationType: "application",
buildLink, buildLink,
adminId: application.project.adminId,
}); });
} catch (error) { } catch (error) {
// @ts-ignore // @ts-ignore
@@ -336,6 +339,7 @@ export const deployRemoteApplication = async ({
// @ts-ignore // @ts-ignore
errorMessage: error?.message || "Error to build", errorMessage: error?.message || "Error to build",
buildLink, buildLink,
adminId: application.project.adminId,
}); });
console.log( console.log(

View File

@@ -235,6 +235,7 @@ export const deployCompose = async ({
applicationName: compose.name, applicationName: compose.name,
applicationType: "compose", applicationType: "compose",
buildLink, buildLink,
adminId: compose.project.adminId,
}); });
} catch (error) { } catch (error) {
await updateDeploymentStatus(deployment.deploymentId, "error"); await updateDeploymentStatus(deployment.deploymentId, "error");
@@ -248,6 +249,7 @@ export const deployCompose = async ({
// @ts-ignore // @ts-ignore
errorMessage: error?.message || "Error to build", errorMessage: error?.message || "Error to build",
buildLink, buildLink,
adminId: compose.project.adminId,
}); });
throw error; throw error;
} }
@@ -353,6 +355,7 @@ export const deployRemoteCompose = async ({
applicationName: compose.name, applicationName: compose.name,
applicationType: "compose", applicationType: "compose",
buildLink, buildLink,
adminId: compose.project.adminId,
}); });
} catch (error) { } catch (error) {
// @ts-ignore // @ts-ignore
@@ -376,6 +379,7 @@ export const deployRemoteCompose = async ({
// @ts-ignore // @ts-ignore
errorMessage: error?.message || "Error to build", errorMessage: error?.message || "Error to build",
buildLink, buildLink,
adminId: compose.project.adminId,
}); });
throw error; throw error;
} }

View File

@@ -49,6 +49,7 @@ export const runMariadbBackup = async (
projectName: project.name, projectName: project.name,
databaseType: "mariadb", databaseType: "mariadb",
type: "success", type: "success",
adminId: project.adminId,
}); });
} catch (error) { } catch (error) {
console.log(error); console.log(error);
@@ -59,6 +60,7 @@ export const runMariadbBackup = async (
type: "error", type: "error",
// @ts-ignore // @ts-ignore
errorMessage: error?.message || "Error message not provided", errorMessage: error?.message || "Error message not provided",
adminId: project.adminId,
}); });
throw error; throw error;
} }

View File

@@ -46,6 +46,7 @@ export const runMongoBackup = async (mongo: Mongo, backup: BackupSchedule) => {
projectName: project.name, projectName: project.name,
databaseType: "mongodb", databaseType: "mongodb",
type: "success", type: "success",
adminId: project.adminId,
}); });
} catch (error) { } catch (error) {
console.log(error); console.log(error);
@@ -56,6 +57,7 @@ export const runMongoBackup = async (mongo: Mongo, backup: BackupSchedule) => {
type: "error", type: "error",
// @ts-ignore // @ts-ignore
errorMessage: error?.message || "Error message not provided", errorMessage: error?.message || "Error message not provided",
adminId: project.adminId,
}); });
throw error; throw error;
} }

View File

@@ -46,6 +46,7 @@ export const runMySqlBackup = async (mysql: MySql, backup: BackupSchedule) => {
projectName: project.name, projectName: project.name,
databaseType: "mysql", databaseType: "mysql",
type: "success", type: "success",
adminId: project.adminId,
}); });
} catch (error) { } catch (error) {
console.log(error); console.log(error);
@@ -56,6 +57,7 @@ export const runMySqlBackup = async (mysql: MySql, backup: BackupSchedule) => {
type: "error", type: "error",
// @ts-ignore // @ts-ignore
errorMessage: error?.message || "Error message not provided", errorMessage: error?.message || "Error message not provided",
adminId: project.adminId,
}); });
throw error; throw error;
} }

View File

@@ -49,6 +49,7 @@ export const runPostgresBackup = async (
projectName: project.name, projectName: project.name,
databaseType: "postgres", databaseType: "postgres",
type: "success", type: "success",
adminId: project.adminId,
}); });
} catch (error) { } catch (error) {
await sendDatabaseBackupNotifications({ await sendDatabaseBackupNotifications({
@@ -58,6 +59,7 @@ export const runPostgresBackup = async (
type: "error", type: "error",
// @ts-ignore // @ts-ignore
errorMessage: error?.message || "Error message not provided", errorMessage: error?.message || "Error message not provided",
adminId: project.adminId,
}); });
throw error; throw error;

View File

@@ -2,7 +2,7 @@ import { db } from "@dokploy/server/db";
import { notifications } from "@dokploy/server/db/schema"; import { notifications } from "@dokploy/server/db/schema";
import BuildFailedEmail from "@dokploy/server/emails/emails/build-failed"; import BuildFailedEmail from "@dokploy/server/emails/emails/build-failed";
import { renderAsync } from "@react-email/components"; import { renderAsync } from "@react-email/components";
import { eq } from "drizzle-orm"; import { and, eq } from "drizzle-orm";
import { import {
sendDiscordNotification, sendDiscordNotification,
sendEmailNotification, sendEmailNotification,
@@ -16,6 +16,7 @@ interface Props {
applicationType: string; applicationType: string;
errorMessage: string; errorMessage: string;
buildLink: string; buildLink: string;
adminId: string;
} }
export const sendBuildErrorNotifications = async ({ export const sendBuildErrorNotifications = async ({
@@ -24,10 +25,14 @@ export const sendBuildErrorNotifications = async ({
applicationType, applicationType,
errorMessage, errorMessage,
buildLink, buildLink,
adminId,
}: Props) => { }: Props) => {
const date = new Date(); const date = new Date();
const notificationList = await db.query.notifications.findMany({ const notificationList = await db.query.notifications.findMany({
where: eq(notifications.appBuildError, true), where: and(
eq(notifications.appBuildError, true),
eq(notifications.adminId, adminId),
),
with: { with: {
email: true, email: true,
discord: true, discord: true,

View File

@@ -2,7 +2,7 @@ import { db } from "@dokploy/server/db";
import { notifications } from "@dokploy/server/db/schema"; import { notifications } from "@dokploy/server/db/schema";
import BuildSuccessEmail from "@dokploy/server/emails/emails/build-success"; import BuildSuccessEmail from "@dokploy/server/emails/emails/build-success";
import { renderAsync } from "@react-email/components"; import { renderAsync } from "@react-email/components";
import { eq } from "drizzle-orm"; import { and, eq } from "drizzle-orm";
import { import {
sendDiscordNotification, sendDiscordNotification,
sendEmailNotification, sendEmailNotification,
@@ -15,6 +15,7 @@ interface Props {
applicationName: string; applicationName: string;
applicationType: string; applicationType: string;
buildLink: string; buildLink: string;
adminId: string;
} }
export const sendBuildSuccessNotifications = async ({ export const sendBuildSuccessNotifications = async ({
@@ -22,10 +23,14 @@ export const sendBuildSuccessNotifications = async ({
applicationName, applicationName,
applicationType, applicationType,
buildLink, buildLink,
adminId,
}: Props) => { }: Props) => {
const date = new Date(); const date = new Date();
const notificationList = await db.query.notifications.findMany({ const notificationList = await db.query.notifications.findMany({
where: eq(notifications.appDeploy, true), where: and(
eq(notifications.appDeploy, true),
eq(notifications.adminId, adminId),
),
with: { with: {
email: true, email: true,
discord: true, discord: true,

View File

@@ -2,7 +2,7 @@ import { db } from "@dokploy/server/db";
import { notifications } from "@dokploy/server/db/schema"; import { notifications } from "@dokploy/server/db/schema";
import DatabaseBackupEmail from "@dokploy/server/emails/emails/database-backup"; import DatabaseBackupEmail from "@dokploy/server/emails/emails/database-backup";
import { renderAsync } from "@react-email/components"; import { renderAsync } from "@react-email/components";
import { eq } from "drizzle-orm"; import { and, eq } from "drizzle-orm";
import { import {
sendDiscordNotification, sendDiscordNotification,
sendEmailNotification, sendEmailNotification,
@@ -16,16 +16,21 @@ export const sendDatabaseBackupNotifications = async ({
databaseType, databaseType,
type, type,
errorMessage, errorMessage,
adminId,
}: { }: {
projectName: string; projectName: string;
applicationName: string; applicationName: string;
databaseType: "postgres" | "mysql" | "mongodb" | "mariadb"; databaseType: "postgres" | "mysql" | "mongodb" | "mariadb";
type: "error" | "success"; type: "error" | "success";
adminId: string;
errorMessage?: string; errorMessage?: string;
}) => { }) => {
const date = new Date(); const date = new Date();
const notificationList = await db.query.notifications.findMany({ const notificationList = await db.query.notifications.findMany({
where: eq(notifications.databaseBackup, true), where: and(
eq(notifications.databaseBackup, true),
eq(notifications.adminId, adminId),
),
with: { with: {
email: true, email: true,
discord: true, discord: true,

View File

@@ -2,7 +2,7 @@ import { db } from "@dokploy/server/db";
import { notifications } from "@dokploy/server/db/schema"; import { notifications } from "@dokploy/server/db/schema";
import DockerCleanupEmail from "@dokploy/server/emails/emails/docker-cleanup"; import DockerCleanupEmail from "@dokploy/server/emails/emails/docker-cleanup";
import { renderAsync } from "@react-email/components"; import { renderAsync } from "@react-email/components";
import { eq } from "drizzle-orm"; import { and, eq } from "drizzle-orm";
import { import {
sendDiscordNotification, sendDiscordNotification,
sendEmailNotification, sendEmailNotification,
@@ -11,11 +11,15 @@ import {
} from "./utils"; } from "./utils";
export const sendDockerCleanupNotifications = async ( export const sendDockerCleanupNotifications = async (
adminId: string,
message = "Docker cleanup for dokploy", message = "Docker cleanup for dokploy",
) => { ) => {
const date = new Date(); const date = new Date();
const notificationList = await db.query.notifications.findMany({ const notificationList = await db.query.notifications.findMany({
where: eq(notifications.dockerCleanup, true), where: and(
eq(notifications.dockerCleanup, true),
eq(notifications.adminId, adminId),
),
with: { with: {
email: true, email: true,
discord: true, discord: true,