mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: update
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import { IS_CLOUD, paths } from "@dokploy/server/constants";
|
||||
import { updateAdmin } from "@dokploy/server/services/admin";
|
||||
import { type RotatingFileStream, createStream } from "rotating-file-stream";
|
||||
import { db } from "../../db";
|
||||
import { execAsync } from "../process/execAsync";
|
||||
@@ -23,27 +22,27 @@ class LogRotationManager {
|
||||
}
|
||||
|
||||
private async initialize(): Promise<void> {
|
||||
// const isActive = await this.getStateFromDB();
|
||||
// if (isActive) {
|
||||
// await this.activateStream();
|
||||
// }
|
||||
const isActive = await this.getStateFromDB();
|
||||
if (isActive) {
|
||||
await this.activateStream();
|
||||
}
|
||||
}
|
||||
|
||||
// private async getStateFromDB(): Promise<boolean> {
|
||||
// const setting = await db.query.admins.findFirst({});
|
||||
// return setting?.enableLogRotation ?? false;
|
||||
// }
|
||||
private async getStateFromDB(): Promise<boolean> {
|
||||
const setting = await db.query.admins.findFirst({});
|
||||
return setting?.enableLogRotation ?? false;
|
||||
}
|
||||
|
||||
// private async setStateInDB(active: boolean): Promise<void> {
|
||||
// const admin = await db.query.admins.findFirst({});
|
||||
private async setStateInDB(active: boolean): Promise<void> {
|
||||
const admin = await db.query.admins.findFirst({});
|
||||
|
||||
// if (!admin) {
|
||||
// return;
|
||||
// }
|
||||
// await updateAdmin(admin?.authId, {
|
||||
// enableLogRotation: active,
|
||||
// });
|
||||
// }
|
||||
if (!admin) {
|
||||
return;
|
||||
}
|
||||
// await updateAdmin(admin?.authId, {
|
||||
// enableLogRotation: active,
|
||||
// });
|
||||
}
|
||||
|
||||
private async activateStream(): Promise<void> {
|
||||
const { DYNAMIC_TRAEFIK_PATH } = paths();
|
||||
|
||||
@@ -49,7 +49,7 @@ export const runMariadbBackup = async (
|
||||
projectName: project.name,
|
||||
databaseType: "mariadb",
|
||||
type: "success",
|
||||
userId: project.userId,
|
||||
organizationId: project.organizationId,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -60,7 +60,7 @@ export const runMariadbBackup = async (
|
||||
type: "error",
|
||||
// @ts-ignore
|
||||
errorMessage: error?.message || "Error message not provided",
|
||||
userId: project.userId,
|
||||
organizationId: project.organizationId,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export const runMongoBackup = async (mongo: Mongo, backup: BackupSchedule) => {
|
||||
projectName: project.name,
|
||||
databaseType: "mongodb",
|
||||
type: "success",
|
||||
userId: project.userId,
|
||||
organizationId: project.organizationId,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -57,7 +57,7 @@ export const runMongoBackup = async (mongo: Mongo, backup: BackupSchedule) => {
|
||||
type: "error",
|
||||
// @ts-ignore
|
||||
errorMessage: error?.message || "Error message not provided",
|
||||
userId: project.userId,
|
||||
organizationId: project.organizationId,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ export const runMySqlBackup = async (mysql: MySql, backup: BackupSchedule) => {
|
||||
projectName: project.name,
|
||||
databaseType: "mysql",
|
||||
type: "success",
|
||||
userId: project.userId,
|
||||
organizationId: project.organizationId,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
@@ -57,7 +57,7 @@ export const runMySqlBackup = async (mysql: MySql, backup: BackupSchedule) => {
|
||||
type: "error",
|
||||
// @ts-ignore
|
||||
errorMessage: error?.message || "Error message not provided",
|
||||
userId: project.userId,
|
||||
organizationId: project.organizationId,
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ export const runPostgresBackup = async (
|
||||
projectName: project.name,
|
||||
databaseType: "postgres",
|
||||
type: "success",
|
||||
userId: project.userId,
|
||||
organizationId: project.organizationId,
|
||||
});
|
||||
} catch (error) {
|
||||
await sendDatabaseBackupNotifications({
|
||||
@@ -59,7 +59,7 @@ export const runPostgresBackup = async (
|
||||
type: "error",
|
||||
// @ts-ignore
|
||||
errorMessage: error?.message || "Error message not provided",
|
||||
userId: project.userId,
|
||||
organizationId: project.organizationId,
|
||||
});
|
||||
|
||||
throw error;
|
||||
|
||||
@@ -19,13 +19,13 @@ export const sendDatabaseBackupNotifications = async ({
|
||||
databaseType,
|
||||
type,
|
||||
errorMessage,
|
||||
userId,
|
||||
organizationId,
|
||||
}: {
|
||||
projectName: string;
|
||||
applicationName: string;
|
||||
databaseType: "postgres" | "mysql" | "mongodb" | "mariadb";
|
||||
type: "error" | "success";
|
||||
userId: string;
|
||||
organizationId: string;
|
||||
errorMessage?: string;
|
||||
}) => {
|
||||
const date = new Date();
|
||||
@@ -33,7 +33,7 @@ export const sendDatabaseBackupNotifications = async ({
|
||||
const notificationList = await db.query.notifications.findMany({
|
||||
where: and(
|
||||
eq(notifications.databaseBackup, true),
|
||||
eq(notifications.userId, userId),
|
||||
eq(notifications.organizationId, organizationId),
|
||||
),
|
||||
with: {
|
||||
email: true,
|
||||
|
||||
Reference in New Issue
Block a user