Repository navigation
Let a system job drop its finished runs and add a non-waiting lock - #2707
Draft
ravikiranvm wants to merge 1 commit into
Draft
ravikiranvm wants to merge 1 commit into
ravikiranvm wants to merge 1 commit into
Conversation
A job definition can set discardFinishedRuns so the queue removes each run once it ends; the queue keeps every finished run by default and scans them on each schedule change. distributedLock.tryAcquireLock takes a lock only if it is free and returns null otherwise, for work that should be skipped while another run of it is going. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Active lock-acquisition issues can cause indefinite waits because reused memory mutexes ignore later timeouts and distributed try-acquisition leaves Redis transport retries unbounded.
2 open issues
What changed in this PR
Adds opt-in cleanup and non-waiting lock acquisition for frequent background jobs, while preserving default job retention.
Changes:
- Adds
discardFinishedRunsto remove completed and failed queue runs. - Adds try-acquisition for Redis and in-memory locks.
- Adds focused tests for retention, contention, and error handling.
Blocking: Two required fixes remain.
Non-blocking: None.
Merge recommendation: Do not merge
| File | Description |
|---|---|
packages/server/shared/test/memory-lock.test.ts |
Tests in-memory try-acquisition and shared ownership. |
packages/server/shared/test/distributed-lock.test.ts |
Tests Redis acquisition, contention, and failures. |
packages/server/shared/src/lib/memory-lock.ts |
Adds in-memory try-acquisition. |
packages/server/shared/src/lib/distributed-lock.ts |
Adds try-acquisition and Redis error classification. |
packages/server/api/test/unit/helper/system-jobs/redis-system-job.test.ts |
Tests default and opt-in retention options. |
packages/server/api/src/app/helper/system-jobs/redis-system-job.ts |
Applies finished-run removal options. |
packages/server/api/src/app/helper/system-jobs/common.ts |
Adds the optional job-retention flag. |
Review effort: Balanced
This branch has not been deployed
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.




Part of OPS-5063.
Two small additions for background jobs that run often. Nothing uses them in this repo yet, and existing jobs and existing lock callers behave as before.
discardFinishedRunsflag. When it is set, the queue removes each run once it completes or fails. Without it, as today, every finished run is kept.distributedLock.tryAcquireLock({ key, timeout })returns the lock, ornullwhen someone else holds it. It never waits.timeoutis how long the lock lives if it is not released.Additional Notes
Why:
acquireLockcan only wait, for up to about twice the lock's lifetime, which would hold up the single worker all system jobs share.Details:
tryAcquireLockmakes one attempt with no retries. It returnsnullonly when Redis reports the key as locked; any other failure is reported and thrown, so a Redis problem is not mistaken for "another run is still going".Considered and not chosen:
acquireLockwith a short timeout and treating the error as "held". With Redis the timeout is also the lock's lifetime, so a short timeout gives a lock that expires in the middle of a long run.Testing Checklist
What was run:
nx build.🤖 Generated with Claude Code