Files
dokploy/apps/dokploy/server/utils/docker-cleanup.ts
Mauricio Siu e6fc3db08f 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>
2026-06-06 14:21:57 -06:00

40 lines
823 B
TypeScript

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();
}
}
};