-
Notifications
You must be signed in to change notification settings - Fork 390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(drain): consider checking parent jobs when draining #992
Merged
roggervalf
merged 15 commits into
master
from
fix-consider-parent-dependencies-in-drain
Jan 28, 2022
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
b4e7d5a
fix(drain): consider checking parent jobs when draining
roggervalf 72cdfb4
refactor(remove-job): consider hard-delete for parent jobs
roggervalf b8afe2f
refactor(dran-obliterate): pass timestamp
roggervalf e288a29
fix(count): consider waiting-children state
roggervalf 939b7d8
test(obliterate): add flow test cases
roggervalf 6b4ca19
docs(removing-job): add documentation
roggervalf 5886c6a
docs(queues): adding removing jobs section
roggervalf ab7b19f
docs(removing-jobs): rewrite warnings
roggervalf 2983a7e
chore: separate phrases in 2 blocks
roggervalf 64eef6d
refactor(include): do not move parent to failed
roggervalf 7ab9482
refactor: separate duplicated code into function
roggervalf a9c711e
refactor: adjust documentation
roggervalf ffb974b
chore: merge branch master
roggervalf 74479e3
docs(removing-job): change typos
roggervalf 745349d
docs(removing-jobs): change typo
roggervalf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Removing job | ||
|
||
Sometimes it is necessary to remove a job. For example there could be a job that has bad data. | ||
|
||
```typescript | ||
import { Queue } from 'bullmq'; | ||
|
||
const queue = new Queue('paint'); | ||
|
||
const job = await queue.add('wall', { color: 1 }); | ||
|
||
await job.remove(); | ||
``` | ||
|
||
{% hint style="info" %} | ||
Locked jobs (in active state) can not be removed. An error will be thrown. | ||
{% endhint %} | ||
|
||
# Having a parent job | ||
|
||
There are 2 possible cases: | ||
|
||
1. There are not pending dependencies; in this case the parent is moved to wait status, we may try to process this job. | ||
2. There are pending dependencies; in this case the parent is kept in waiting-children status. | ||
|
||
# Having pending dependencies | ||
|
||
We may try to remove all its pending descendents first. | ||
|
||
{% hint style="warning" %} | ||
In case one of the children is locked, it will stop the deletion process. | ||
{% endhint %} |
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
Currently we have 2 available methods in queue class: | ||
|
||
# Drain | ||
|
||
Removes all jobs that are waiting or delayed, but not active, completed or failed. | ||
|
||
```typescript | ||
import { Queue } from 'bullmq'; | ||
|
||
const queue = new Queue('paint'); | ||
|
||
await queue.drain(); | ||
``` | ||
|
||
{% hint style="warning" %} | ||
Parent jobs that belong to the queue being drained will be kept in **waiting-children** status if they have pending children, but if they do not have any pending children they will just be removed. | ||
{% endhint %} | ||
|
||
{% hint style="warning" %} | ||
Parent jobs in queues different from the one being drained will either stay in **waiting-children** if they | ||
have pending children in other queues, or just moved to wait. | ||
{% endhint %} | ||
|
||
# Obliterate | ||
|
||
Completely obliterates a queue and all of its contents. | ||
|
||
```typescript | ||
import { Queue } from 'bullmq'; | ||
|
||
const queue = new Queue('paint'); | ||
|
||
await queue.obliterate(); | ||
``` | ||
|
||
{% hint style="warning" %} | ||
Parent jobs in queues different from the one being obliterated will either stay in **waiting-children** if they | ||
have pending children in other queues, or just moved to wait. | ||
{% endhint %} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
--[[ | ||
Functions remove jobs. | ||
]] | ||
local function getListItems(keyName, max) | ||
return rcall('LRANGE', keyName, 0, max - 1) | ||
end | ||
|
||
local function getZSetItems(keyName, max) | ||
return rcall('ZRANGE', keyName, 0, max - 1) | ||
end | ||
|
||
--- @include "removeParentDependencyKey" | ||
|
||
local function removeJobs(keys, hard, baseKey, max) | ||
for i, key in ipairs(keys) do | ||
local jobKey = baseKey .. key | ||
removeParentDependencyKey(jobKey, hard, baseKey) | ||
rcall("DEL", jobKey) | ||
rcall("DEL", jobKey .. ':logs') | ||
rcall("DEL", jobKey .. ':dependencies') | ||
rcall("DEL", jobKey .. ':processed') | ||
end | ||
return max - #keys | ||
end | ||
|
||
local function removeListJobs(keyName, hard, baseKey, max) | ||
local jobs = getListItems(keyName, max) | ||
local count = removeJobs(jobs, hard, baseKey, max) | ||
rcall("LTRIM", keyName, #jobs, -1) | ||
return count | ||
end | ||
|
||
local function removeZSetJobs(keyName, hard, baseKey, max) | ||
local jobs = getZSetItems(keyName, max) | ||
local count = removeJobs(jobs, hard, baseKey, max) | ||
if(#jobs > 0) then | ||
rcall("ZREM", keyName, unpack(jobs)) | ||
end | ||
return count | ||
end |
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should only delete those records that belongs to the same queue that runs this script, on the contrary case, move it to wait or paused