mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
feat(notifications): add emails and methos for each action
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { unlink } from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import type { BackupSchedule } from "@/server/api/services/backup";
|
||||
import { sendDatabaseBackupNotifications } from "@/server/api/services/notification";
|
||||
import type { Postgres } from "@/server/api/services/postgres";
|
||||
import { findProjectById } from "@/server/api/services/project";
|
||||
import { getServiceContainer } from "../docker/utils";
|
||||
import { execAsync } from "../process/execAsync";
|
||||
import { uploadToS3 } from "./utils";
|
||||
@@ -10,7 +12,9 @@ export const runPostgresBackup = async (
|
||||
postgres: Postgres,
|
||||
backup: BackupSchedule,
|
||||
) => {
|
||||
const { appName, databaseUser } = postgres;
|
||||
const { appName, databaseUser, name, projectId } = postgres;
|
||||
const project = await findProjectById(projectId);
|
||||
|
||||
const { prefix, database } = backup;
|
||||
const destination = backup.destination;
|
||||
const backupFileName = `${new Date().toISOString()}.sql.gz`;
|
||||
@@ -29,8 +33,21 @@ export const runPostgresBackup = async (
|
||||
await execAsync(`docker cp ${containerId}:${containerPath} ${hostPath}`);
|
||||
|
||||
await uploadToS3(destination, bucketDestination, hostPath);
|
||||
await sendDatabaseBackupNotifications({
|
||||
applicationName: name,
|
||||
projectName: project.name,
|
||||
databaseType: "postgres",
|
||||
type: "success",
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
await sendDatabaseBackupNotifications({
|
||||
applicationName: name,
|
||||
projectName: project.name,
|
||||
databaseType: "postgres",
|
||||
type: "error",
|
||||
errorMessage: error?.message || "Error message not provided",
|
||||
});
|
||||
|
||||
throw error;
|
||||
} finally {
|
||||
await unlink(hostPath);
|
||||
|
||||
Reference in New Issue
Block a user