fix(schedules): remove the repeatable job that is actually registered - #5459
Open
Dev-next-gen wants to merge 1 commit into
Open
Dev-next-gen wants to merge 1 commit into
Dev-next-gen wants to merge 1 commit into
Conversation
/remove-job passed the caller's cronSchedule straight to removeRepeatable, so the BullMQ key was rebuilt from the cron stored in the database. When that value has drifted from the pattern the live repeatable was registered with, the key does not match, nothing is removed and the job keeps firing. /update-backup already avoided this by resolving the job with getJobRepeatable and removing it with job.pattern. Do that resolution inside removeJob, so every caller gets it: the delete paths of backups, schedules and volume backups, and the server cleanup. The per-type block in /update-backup becomes redundant and is dropped. Removing a job that is already gone still returns false instead of throwing, so the callers that ignore the result keep working as before.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this PR about?
While reviewing #5454 I was pointed at the schedules service, and the mismatch is there rather than in the routers.
/remove-jobpasses thecronScheduleit receives straight tojobQueue.removeRepeatable, which rebuilds the BullMQ repeatable key from that value. The cron the callers send comes from the database row, and it can already have been replaced by an earlier update that never reached the queue, so the rebuilt key does not match the pattern the live repeatable was registered with. Nothing is removed, the endpoint answersresult: false, and the job keeps firing. The same happens when only the timezone of a schedule changed./update-backup, a few lines above in the same file, already avoids this: it looks the job up withgetJobRepeatableand removes it withjob.pattern, ignoring the cron the caller sent. I moved that resolution intoremoveJobitself, so/remove-jobgets it too and all four callers benefit at once:backup.remove,schedule.delete,volumeBackups.delete(and the disable branch ofvolumeBackups.update), and the server cleanup insettings.ts. None of them needed a change. The per-type block in/update-backupbecame redundant and is gone, which is where most of the deleted lines come from.Removing a job that is not registered anymore still returns
falserather than throwing, so the callers that ignore the result behave exactly as before.I added
apps/dokploy/__test__/schedules/remove-job-live-pattern.test.ts, which registers a repeatable, simulates the stored cron drifting, and callsremoveJobwith the new value. Oncanarythe three drift cases fail (removeRepeatablereturnsfalseand the job survives); with this change the six tests pass.pnpm --filter=@dokploy/schedules typecheckand the dokploytsc --noEmitare clean, andbiome checkreports nothing new on the touched files.Checklist
Before submitting this PR, please make sure that:
canarybranch.Issues related (if applicable)
Follow-up to the review discussion on #5454: #5454 (comment)
AI tools used
This PR appears safe to merge.
Summary
Reviews (1) · Last reviewed commit: "fix(schedules): remove the repeatable jo..."