-
Notifications
You must be signed in to change notification settings - Fork 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(drain): consider checking parent jobs when draining (#992)
- Loading branch information
1 parent
e55ff35
commit 81b7221
Showing
12 changed files
with
588 additions
and
154 deletions.
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.