mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
fix: remove cron jobs after delete service
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
apiSaveExternalPortMariaDB,
|
||||
apiUpdateMariaDB,
|
||||
} from "@/server/db/schema";
|
||||
import { cancelJobs } from "@/server/utils/backup";
|
||||
import {
|
||||
IS_CLOUD,
|
||||
addNewService,
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
createMariadb,
|
||||
createMount,
|
||||
deployMariadb,
|
||||
findBackupsByDbId,
|
||||
findMariadbById,
|
||||
findProjectById,
|
||||
findServerById,
|
||||
@@ -211,8 +213,10 @@ export const mariadbRouter = createTRPCRouter({
|
||||
});
|
||||
}
|
||||
|
||||
const backups = await findBackupsByDbId(input.mariadbId, "mariadb");
|
||||
const cleanupOperations = [
|
||||
async () => await removeService(mongo?.appName, mongo.serverId),
|
||||
async () => await cancelJobs(backups),
|
||||
async () => await removeMariadbById(input.mariadbId),
|
||||
];
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
apiSaveExternalPortMongo,
|
||||
apiUpdateMongo,
|
||||
} from "@/server/db/schema";
|
||||
import { cancelJobs } from "@/server/utils/backup";
|
||||
import {
|
||||
IS_CLOUD,
|
||||
addNewService,
|
||||
@@ -16,6 +17,7 @@ import {
|
||||
createMongo,
|
||||
createMount,
|
||||
deployMongo,
|
||||
findBackupsByDbId,
|
||||
findMongoById,
|
||||
findProjectById,
|
||||
removeMongoById,
|
||||
@@ -252,9 +254,11 @@ export const mongoRouter = createTRPCRouter({
|
||||
message: "You are not authorized to delete this mongo",
|
||||
});
|
||||
}
|
||||
const backups = await findBackupsByDbId(input.mongoId, "mongo");
|
||||
|
||||
const cleanupOperations = [
|
||||
async () => await removeService(mongo?.appName, mongo.serverId),
|
||||
async () => await cancelJobs(backups),
|
||||
async () => await removeMongoById(input.mongoId),
|
||||
];
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
createMount,
|
||||
createMysql,
|
||||
deployMySql,
|
||||
findBackupsByDbId,
|
||||
findMySqlById,
|
||||
findProjectById,
|
||||
removeMySqlById,
|
||||
@@ -30,6 +31,7 @@ import {
|
||||
updateMySqlById,
|
||||
} from "@dokploy/server";
|
||||
import { observable } from "@trpc/server/observable";
|
||||
import { cancelJobs } from "@/server/utils/backup";
|
||||
|
||||
export const mysqlRouter = createTRPCRouter({
|
||||
create: protectedProcedure
|
||||
@@ -249,8 +251,10 @@ export const mysqlRouter = createTRPCRouter({
|
||||
});
|
||||
}
|
||||
|
||||
const backups = await findBackupsByDbId(input.mysqlId, "mysql");
|
||||
const cleanupOperations = [
|
||||
async () => await removeService(mongo?.appName, mongo.serverId),
|
||||
async () => await cancelJobs(backups),
|
||||
async () => await removeMySqlById(input.mysqlId),
|
||||
];
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import {
|
||||
createMount,
|
||||
createPostgres,
|
||||
deployPostgres,
|
||||
findBackupsByDbId,
|
||||
findPostgresById,
|
||||
findProjectById,
|
||||
removePostgresById,
|
||||
@@ -34,6 +35,7 @@ import {
|
||||
import { TRPCError } from "@trpc/server";
|
||||
import { observable } from "@trpc/server/observable";
|
||||
import { z } from "zod";
|
||||
import { cancelJobs } from "@/server/utils/backup";
|
||||
|
||||
const ee = new EventEmitter();
|
||||
|
||||
@@ -231,8 +233,11 @@ export const postgresRouter = createTRPCRouter({
|
||||
});
|
||||
}
|
||||
|
||||
const backups = await findBackupsByDbId(input.postgresId, "postgres");
|
||||
|
||||
const cleanupOperations = [
|
||||
removeService(postgres.appName, postgres.serverId),
|
||||
cancelJobs(backups),
|
||||
removePostgresById(input.postgresId),
|
||||
];
|
||||
|
||||
|
||||
@@ -244,7 +244,6 @@ export const redisRouter = createTRPCRouter({
|
||||
message: "You are not authorized to delete this Redis",
|
||||
});
|
||||
}
|
||||
|
||||
const cleanupOperations = [
|
||||
async () => await removeService(redis?.appName, redis.serverId),
|
||||
async () => await removeRedisById(input.redisId),
|
||||
|
||||
@@ -1,3 +1,10 @@
|
||||
import {
|
||||
type BackupScheduleList,
|
||||
IS_CLOUD,
|
||||
removeScheduleBackup,
|
||||
scheduleBackup,
|
||||
} from "@dokploy/server/index";
|
||||
|
||||
type QueueJob =
|
||||
| {
|
||||
type: "backup";
|
||||
@@ -59,3 +66,19 @@ export const updateJob = async (job: QueueJob) => {
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
export const cancelJobs = async (backups: BackupScheduleList) => {
|
||||
for (const backup of backups) {
|
||||
if (backup.enabled) {
|
||||
if (IS_CLOUD) {
|
||||
await removeJob({
|
||||
cronSchedule: backup.schedule,
|
||||
backupId: backup.backupId,
|
||||
type: "backup",
|
||||
});
|
||||
} else {
|
||||
removeScheduleBackup(backup.backupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user