feat(queue): honest job-state tracking for the in-memory queue#12
Merged
Conversation
- InMemoryQueue tracks the full state machine (delayed -> waiting -> active -> completed | failed); retry backoff parks the job as delayed via the new _retryLater handshake. - getJobs(states) honors its argument; new getJobCounts(...states). - removeOnComplete/removeOnFail honored; retained completed/failed history capped at 1000 each (oldest dropped). - obliterate() cancels pending delay/backoff timers (an obliterated delayed job never runs); queue.close() delegates to it. - Worker close(force?) waits for in-flight jobs by default (BullMQ semantics); 'drained' emitted once per drain; queue-level 'completed'/'failed' events mirror the worker's. - 9 new tests (45 total). New exported JobState type. - No version bump: rides with the next release.
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.
Upgrades the BullMQ-shaped in-memory queue from "fan-out only" to honest job-state tracking, closing the gap between what the API accepts and what it actually does (
getJobs(states)ignored its argument;removeOnComplete/removeOnFailwere accepted but unused).Added
delayed → waiting → active → completed | failed. A retrying job (backoff timer pending) counts asdelayeduntil re-enqueued.getJobs(states)now honors its argument (unknown names ignored); newgetJobCounts(...states)— all five states with no args.removeOnComplete/removeOnFailhonored; retained completed/failed history capped at 1000 each (oldest dropped) so a long-lived dev process doesn't leak.Worker#close(force?)waits for in-flight jobs by default (BullMQ semantics);force=trueskips the wait. No new jobs start once closing.'drained'event on the worker — once per drain, not per idle poll. Delayed jobs don't block a drain, matching BullMQ.'completed'/'failed'events mirroring the worker's (a deliberate simplification of BullMQ's separate QueueEvents class).obliterate()cancels pending delay/backoff timers — an obliterated delayed job never runs.queue.close()now delegates to it (previously orphaned timers could fire after close).JobStatetype.Tests
45/45 (was 36): state transitions via getJobs/getJobCounts, retry lands in delayed then re-runs, removeOnComplete/Fail, close() provably waits for the in-flight job, close(true) doesn't, drained-fires-once, obliterate cancels delayed, queue-level events.
Release note
No version bump in this PR — v0.1.0's npm publish is pending the NPM_TOKEN fix; this rides under
[Unreleased]and ships with the next bump.