From e59ba0636b32c048d33cb6c9275dcc38567fc773 Mon Sep 17 00:00:00 2001 From: Mauricio Siu Date: Thu, 22 Oct 2026 12:12:37 -0600 Subject: [PATCH] fix: register cloud schedules without a timezone (#5139) --- apps/dokploy/server/api/routers/backup.ts | 2 +- apps/dokploy/server/api/routers/schedule.ts | 2 +- apps/dokploy/server/utils/backup.ts | 65 ++++++--------------- apps/schedules/src/schema.ts | 2 +- 4 files changed, 22 insertions(+), 49 deletions(-) diff --git a/apps/dokploy/server/api/routers/backup.ts b/apps/dokploy/server/api/routers/backup.ts index 9bc73ce77..72aff2587 100644 --- a/apps/dokploy/server/api/routers/backup.ts +++ b/apps/dokploy/server/api/routers/backup.ts @@ -267,7 +267,7 @@ export const backupRouter = createTRPCRouter({ const value = await removeBackupById(input.backupId); if (IS_CLOUD && value) { - removeJob({ + await removeJob({ backupId: input.backupId, cronSchedule: value.schedule, type: "backup", diff --git a/apps/dokploy/server/api/routers/schedule.ts b/apps/dokploy/server/api/routers/schedule.ts index a7417a92c..aae503e50 100644 --- a/apps/dokploy/server/api/routers/schedule.ts +++ b/apps/dokploy/server/api/routers/schedule.ts @@ -66,7 +66,7 @@ export const scheduleRouter = createTRPCRouter({ if (newSchedule?.enabled) { if (IS_CLOUD) { - schedule({ + await schedule({ scheduleId: newSchedule.scheduleId, type: "schedule", cronSchedule: newSchedule.cronExpression, diff --git a/apps/dokploy/server/utils/backup.ts b/apps/dokploy/server/utils/backup.ts index 588f6636b..801e5e774 100644 --- a/apps/dokploy/server/utils/backup.ts +++ b/apps/dokploy/server/utils/backup.ts @@ -26,56 +26,29 @@ type QueueJob = cronSchedule: string; volumeBackupId: string; }; -export const schedule = async (job: QueueJob) => { - try { - const result = await fetch(`${process.env.JOBS_URL}/create-backup`, { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-Key": process.env.API_KEY || "NO-DEFINED", - }, - body: JSON.stringify(job), - }); - const data = await result.json(); - return data; - } catch (error) { - throw error; +const postJob = async (path: string, job: QueueJob) => { + const result = await fetch(`${process.env.JOBS_URL}${path}`, { + method: "POST", + headers: { + "Content-Type": "application/json", + "X-API-Key": process.env.API_KEY || "NO-DEFINED", + }, + body: JSON.stringify(job), + }); + const data = await result.json(); + if (!result.ok) { + throw new Error( + `Jobs service ${path} failed (${result.status}): ${JSON.stringify(data)}`, + ); } + return data; }; -export const removeJob = async (job: QueueJob) => { - try { - const result = await fetch(`${process.env.JOBS_URL}/remove-job`, { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-Key": process.env.API_KEY || "NO-DEFINED", - }, - body: JSON.stringify(job), - }); - const data = await result.json(); - return data; - } catch (error) { - throw error; - } -}; +export const schedule = (job: QueueJob) => postJob("/create-backup", job); -export const updateJob = async (job: QueueJob) => { - try { - const result = await fetch(`${process.env.JOBS_URL}/update-backup`, { - method: "POST", - headers: { - "Content-Type": "application/json", - "X-API-Key": process.env.API_KEY || "NO-DEFINED", - }, - body: JSON.stringify(job), - }); - const data = await result.json(); - return data; - } catch (error) { - throw error; - } -}; +export const removeJob = (job: QueueJob) => postJob("/remove-job", job); + +export const updateJob = (job: QueueJob) => postJob("/update-backup", job); export const cancelJobs = async (backups: BackupScheduleList) => { for (const backup of backups) { diff --git a/apps/schedules/src/schema.ts b/apps/schedules/src/schema.ts index a9467027c..717da399b 100644 --- a/apps/schedules/src/schema.ts +++ b/apps/schedules/src/schema.ts @@ -15,7 +15,7 @@ export const jobQueueSchema = z.discriminatedUnion("type", [ cronSchedule: z.string(), type: z.literal("schedule"), scheduleId: z.string(), - timezone: z.string().optional(), + timezone: z.string().nullish(), }), z.object({ cronSchedule: z.string(),