fix: add docker cleanup toggle to remote server creation (#4559)

* fix: add docker cleanup toggle to remote server creation and update forms

* [autofix.ci] apply automated fixes

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
This commit is contained in:
Mauricio Siu
2026-06-06 14:21:57 -06:00
committed by GitHub
parent 57ef96a458
commit e6fc3db08f
5 changed files with 108 additions and 5 deletions

View File

@@ -45,6 +45,7 @@ import {
redis,
server,
} from "@/server/db/schema";
import { applyDockerCleanupSchedule } from "@/server/utils/docker-cleanup";
export const serverRouter = createTRPCRouter({
create: withPermission("server", "create")
@@ -63,6 +64,11 @@ export const serverRouter = createTRPCRouter({
input,
ctx.session.activeOrganizationId,
);
await applyDockerCleanupSchedule(
project.serverId,
ctx.session.activeOrganizationId,
input.enableDockerCleanup,
);
await audit(ctx, {
action: "create",
resourceType: "server",
@@ -456,6 +462,12 @@ export const serverRouter = createTRPCRouter({
...input,
});
await applyDockerCleanupSchedule(
input.serverId,
ctx.session.activeOrganizationId,
input.enableDockerCleanup,
);
await audit(ctx, {
action: "update",
resourceType: "server",

View File

@@ -0,0 +1,39 @@
import {
CLEANUP_CRON_JOB,
cleanupAll,
IS_CLOUD,
sendDockerCleanupNotifications,
} from "@dokploy/server";
import { scheduledJobs, scheduleJob } from "node-schedule";
import { removeJob, schedule } from "./backup";
export const applyDockerCleanupSchedule = async (
serverId: string,
organizationId: string,
enable: boolean,
) => {
if (enable) {
if (IS_CLOUD) {
await schedule({
cronSchedule: CLEANUP_CRON_JOB,
serverId,
type: "server",
});
} else {
scheduleJob(serverId, CLEANUP_CRON_JOB, async () => {
await cleanupAll(serverId);
await sendDockerCleanupNotifications(organizationId);
});
}
} else {
if (IS_CLOUD) {
await removeJob({
cronSchedule: CLEANUP_CRON_JOB,
serverId,
type: "server",
});
} else {
scheduledJobs[serverId]?.cancel();
}
}
};