Merge pull request #5245 from Dokploy/fix/schedule-cloud-update-orphan-job

fix: orphaned BullMQ job when updating an enabled schedule in cloud
This commit is contained in:
Mauricio Siu 2026-09-01 01:38:12 -06:00 committed by GitHub
commit 48e0b747b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 7 additions and 3 deletions

View File

@ -25,7 +25,7 @@ import { asc, desc, eq } from "drizzle-orm";
import { z } from "zod";
import { audit } from "@/server/api/utils/audit";
import { assertScheduledJobLimit } from "@/server/api/utils/plan-limits";
import { removeJob, schedule } from "@/server/utils/backup";
import { removeJob, schedule, updateJob } from "@/server/utils/backup";
import { createTRPCRouter, protectedProcedure } from "../trpc";
export const scheduleRouter = createTRPCRouter({
@ -130,7 +130,7 @@ export const scheduleRouter = createTRPCRouter({
if (IS_CLOUD) {
if (updatedSchedule?.enabled) {
schedule({
await updateJob({
scheduleId: updatedSchedule.scheduleId,
type: "schedule",
cronSchedule: updatedSchedule.cronExpression,
@ -141,6 +141,7 @@ export const scheduleRouter = createTRPCRouter({
cronSchedule: updatedSchedule.cronExpression,
scheduleId: updatedSchedule.scheduleId,
type: "schedule",
timezone: updatedSchedule.timezone,
});
}
} else {
@ -185,6 +186,7 @@ export const scheduleRouter = createTRPCRouter({
cronSchedule: scheduleItem.cronExpression,
scheduleId: scheduleItem.scheduleId,
type: "schedule",
timezone: scheduleItem.timezone,
});
} else {
removeScheduleJob(scheduleItem.scheduleId);

View File

@ -60,6 +60,7 @@ app.post("/update-backup", zValidator("json", jobQueueSchema), async (c) => {
scheduleId: data.scheduleId,
type: "schedule",
cronSchedule: job.pattern || "",
timezone: job.tz || data.timezone,
});
} else if (data.type === "volume-backup") {
result = await removeJob({

View File

@ -66,9 +66,10 @@ export const removeJob = async (data: QueueJob) => {
return result;
}
if (data.type === "schedule") {
const { scheduleId, cronSchedule } = data;
const { scheduleId, cronSchedule, timezone } = data;
const result = await jobQueue.removeRepeatable(scheduleId, {
pattern: cronSchedule,
tz: timezone || "UTC",
});
return result;
}