feat(notifications): add emails and methos for each action

This commit is contained in:
Mauricio Siu
2024-07-19 01:02:48 -06:00
parent 787506fb6b
commit 2d4eaeb8b5
22 changed files with 7215 additions and 162 deletions

View File

@@ -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);