-
Notifications
You must be signed in to change notification settings - Fork 413
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(job): add removeChildDependency method (#2435)
- Loading branch information
1 parent
ada23fa
commit 1151022
Showing
7 changed files
with
401 additions
and
23 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,31 @@ | ||
# Remove Child Dependency | ||
|
||
In some situations, you may have a parent job and need to remove the dependency of one of its children. | ||
|
||
The pattern to solve this requirement consists on using the **removeChildDependency** method. It will make sure that if the job is the last pending child, to move its parent to _waiting_ and it won't be listed in unprocessed list of the parent. | ||
|
||
```typescript | ||
const flow = new FlowProducer({ connection }); | ||
|
||
const originalTree = await flow.add({ | ||
name: 'root-job', | ||
queueName: 'topQueueName', | ||
data: {}, | ||
children: [ | ||
{ | ||
name, | ||
data: { idx: 0, foo: 'bar' }, | ||
queueName: 'childrenQueueName', | ||
opts: {}, | ||
}, | ||
], | ||
}); | ||
|
||
await originalTree.children[0].job.removeChildDependency(); | ||
``` | ||
|
||
{% hint style="waring" %} | ||
As soon as a **child** calls this method, it will verify if it has an existing parent, if not, it'll throw an error. | ||
{% endhint %} | ||
|
||
Failed or completed children using this option won't generate any removal as they won't be part of unprocessed list: |
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,34 @@ | ||
--[[ | ||
Break parent-child dependency by removing | ||
child reference from parent | ||
Input: | ||
KEYS[1] 'key' prefix, | ||
ARGV[1] job key | ||
ARGV[2] parent key | ||
Output: | ||
0 - OK | ||
1 - There is not relationship. | ||
-1 - Missing job key | ||
-5 - Missing parent key | ||
]] | ||
local rcall = redis.call | ||
local jobKey = ARGV[1] | ||
local parentKey = ARGV[2] | ||
|
||
-- Includes | ||
--- @include "includes/removeParentDependencyKey" | ||
|
||
if rcall("EXISTS", jobKey) ~= 1 then return -1 end | ||
|
||
if rcall("EXISTS", parentKey) ~= 1 then return -5 end | ||
|
||
if removeParentDependencyKey(jobKey, false, parentKey, KEYS[1]) then | ||
rcall("HDEL", jobKey, "parentKey", "parent") | ||
|
||
return 0 | ||
else | ||
return 1 | ||
end |
Oops, something went wrong.