Skip to content

Commit 110bdce

Browse files
committed
feat(schedules): replace hardcoded cron schedule with CLEANUP_CRON_JOB constant
- Updated the cron schedule for Docker cleanup tasks across multiple files to use the new CLEANUP_CRON_JOB constant. - This change enhances maintainability by centralizing the cron schedule configuration, ensuring consistency across the application.
1 parent b9e7002 commit 110bdce

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

apps/dokploy/server/api/routers/settings.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
CLEANUP_CRON_JOB,
23
canAccessToTraefikFiles,
34
checkGPUStatus,
45
checkPortInUse,
@@ -298,12 +299,12 @@ export const settingsRouter = createTRPCRouter({
298299
}
299300
if (IS_CLOUD) {
300301
await schedule({
301-
cronSchedule: "0 0 * * *",
302+
cronSchedule: CLEANUP_CRON_JOB,
302303
serverId: input.serverId,
303304
type: "server",
304305
});
305306
} else {
306-
scheduleJob(server.serverId, "0 0 * * *", async () => {
307+
scheduleJob(server.serverId, CLEANUP_CRON_JOB, async () => {
307308
console.log(
308309
`Docker Cleanup ${new Date().toLocaleString()}] Running...`,
309310
);
@@ -316,7 +317,7 @@ export const settingsRouter = createTRPCRouter({
316317
} else {
317318
if (IS_CLOUD) {
318319
await removeJob({
319-
cronSchedule: "0 0 * * *",
320+
cronSchedule: CLEANUP_CRON_JOB,
320321
serverId: input.serverId,
321322
type: "server",
322323
});
@@ -331,7 +332,7 @@ export const settingsRouter = createTRPCRouter({
331332
});
332333

333334
if (settingsUpdated?.enableDockerCleanup) {
334-
scheduleJob("docker-cleanup", "0 0 * * *", async () => {
335+
scheduleJob("docker-cleanup", CLEANUP_CRON_JOB, async () => {
335336
console.log(
336337
`Docker Cleanup ${new Date().toLocaleString()}] Running...`,
337338
);

apps/schedules/src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import {
2+
CLEANUP_CRON_JOB,
23
cleanupAll,
34
findBackupById,
45
findScheduleById,
@@ -125,7 +126,7 @@ export const initializeJobs = async () => {
125126
scheduleJob({
126127
serverId,
127128
type: "server",
128-
cronSchedule: "0 0 * * *",
129+
cronSchedule: CLEANUP_CRON_JOB,
129130
});
130131
}
131132

packages/server/src/constants/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import path from "node:path";
22
import Docker from "dockerode";
33

44
export const IS_CLOUD = process.env.IS_CLOUD === "true";
5+
export const CLEANUP_CRON_JOB = "50 23 * * *";
56
export const docker = new Docker();
67

78
export const BETTER_AUTH_SECRET =
@@ -29,5 +30,6 @@ export const paths = (isServer = false) => {
2930
REGISTRY_PATH: `${BASE_PATH}/registry`,
3031
SCHEDULES_PATH: `${BASE_PATH}/schedules`,
3132
VOLUME_BACKUPS_PATH: `${BASE_PATH}/volume-backups`,
33+
VOLUME_BACKUP_LOCK_PATH: `${BASE_PATH}/volume-backup-lock`,
3234
};
3335
};

packages/server/src/utils/backups/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import path from "node:path";
2+
import { CLEANUP_CRON_JOB } from "@dokploy/server/constants";
23
import { member } from "@dokploy/server/db/schema";
34
import type { BackupSchedule } from "@dokploy/server/services/backup";
45
import { getAllServers } from "@dokploy/server/services/server";
@@ -29,7 +30,7 @@ export const initCronJobs = async () => {
2930
const webServerSettings = await getWebServerSettings();
3031

3132
if (webServerSettings?.enableDockerCleanup) {
32-
scheduleJob("docker-cleanup", "0 0 * * *", async () => {
33+
scheduleJob("docker-cleanup", CLEANUP_CRON_JOB, async () => {
3334
console.log(
3435
`Docker Cleanup ${new Date().toLocaleString()}] Running docker cleanup`,
3536
);
@@ -45,7 +46,7 @@ export const initCronJobs = async () => {
4546
for (const server of servers) {
4647
const { serverId, enableDockerCleanup, name } = server;
4748
if (enableDockerCleanup) {
48-
scheduleJob(serverId, "0 0 * * *", async () => {
49+
scheduleJob(serverId, CLEANUP_CRON_JOB, async () => {
4950
console.log(
5051
`SERVER-BACKUP[${new Date().toLocaleString()}] Running Cleanup ${name}`,
5152
);

0 commit comments

Comments
 (0)