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

@@ -2,12 +2,15 @@ import { unlink } from "node:fs/promises";
import path from "node:path";
import type { BackupSchedule } from "@/server/api/services/backup";
import type { MySql } from "@/server/api/services/mysql";
import { sendDatabaseBackupNotifications } from "@/server/api/services/notification";
import { findProjectById } from "@/server/api/services/project";
import { getServiceContainer } from "../docker/utils";
import { execAsync } from "../process/execAsync";
import { uploadToS3 } from "./utils";
export const runMySqlBackup = async (mysql: MySql, backup: BackupSchedule) => {
const { appName, databaseRootPassword } = mysql;
const { appName, databaseRootPassword, projectId, name } = mysql;
const project = await findProjectById(projectId);
const { prefix, database } = backup;
const destination = backup.destination;
const backupFileName = `${new Date().toISOString()}.sql.gz`;
@@ -29,8 +32,21 @@ export const runMySqlBackup = async (mysql: MySql, backup: BackupSchedule) => {
`docker cp ${containerId}:/backup/${backupFileName} ${hostPath}`,
);
await uploadToS3(destination, bucketDestination, hostPath);
await sendDatabaseBackupNotifications({
applicationName: name,
projectName: project.name,
databaseType: "mysql",
type: "success",
});
} catch (error) {
console.log(error);
await sendDatabaseBackupNotifications({
applicationName: name,
projectName: project.name,
databaseType: "mysql",
type: "error",
errorMessage: error?.message || "Error message not provided",
});
throw error;
} finally {
await unlink(hostPath);