bullmq 6.7.5 → 6.7.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -8,6 +8,7 @@
8
8
  --- @include "addJobInTargetList"
9
9
  --- @include "destructureJobKey"
10
10
  --- @include "isQueuePausedOrMaxed"
11
+ --- @include "removeDeduplicationKeyIfNeededOnRemoval"
11
12
  --- @include "removeJobKeys"
12
13
 
13
14
  local function _moveParentToWait(parentPrefix, parentId, emitEvent)
@@ -21,7 +22,7 @@ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
21
22
  end
22
23
  end
23
24
 
24
- local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
25
+ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey)
25
26
  if parentKey then
26
27
  local parentDependenciesKey = parentKey .. ":dependencies"
27
28
  local result = rcall("SREM", parentDependenciesKey, jobKey)
@@ -36,11 +37,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
36
37
  if numRemovedElements == 1 then
37
38
  if hard then -- remove parent in same queue
38
39
  if parentPrefix == baseKey then
39
- removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
40
+ local parentDeduplicationId = rcall("HGET", parentKey, "deid")
41
+ removeParentDependencyKey(parentKey, hard, nil, baseKey)
40
42
  removeJobKeys(parentKey)
41
- if debounceId then
42
- rcall("DEL", parentPrefix .. "de:" .. debounceId)
43
- end
43
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
44
44
  else
45
45
  _moveParentToWait(parentPrefix, parentId)
46
46
  end
@@ -52,8 +52,7 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
52
52
  return true
53
53
  end
54
54
  else
55
- local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
56
- local missedParentKey = parentAttributes[1]
55
+ local missedParentKey = rcall("HGET", jobKey, "parentKey")
57
56
  if( (type(missedParentKey) == "string") and missedParentKey ~= ""
58
57
  and (rcall("EXISTS", missedParentKey) == 1)) then
59
58
  local parentDependenciesKey = missedParentKey .. ":dependencies"
@@ -69,11 +68,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
69
68
  if numRemovedElements == 1 then
70
69
  if hard then
71
70
  if parentPrefix == baseKey then
72
- removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
71
+ local parentDeduplicationId = rcall("HGET", missedParentKey, "deid")
72
+ removeParentDependencyKey(missedParentKey, hard, nil, baseKey)
73
73
  removeJobKeys(missedParentKey)
74
- if parentAttributes[2] then
75
- rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
76
- end
74
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
77
75
  else
78
76
  _moveParentToWait(parentPrefix, parentId)
79
77
  end
@@ -191,7 +191,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- Make sure job exists
191
191
  -- TODO: when a child is removed when finished, result or failure in parent
192
192
  -- must not be deleted, those value references should be deleted when the parent
193
193
  -- is deleted
194
- removeParentDependencyKey(jobIdKey, false, parentKey, jobAttributes[3])
194
+ removeParentDependencyKey(jobIdKey, false, parentKey, prefix)
195
195
  end
196
196
  end
197
197
 
@@ -25,7 +25,7 @@ if rcall("EXISTS", jobKey) ~= 1 then return -1 end
25
25
 
26
26
  if rcall("EXISTS", parentKey) ~= 1 then return -5 end
27
27
 
28
- if removeParentDependencyKey(jobKey, false, parentKey, KEYS[1], nil) then
28
+ if removeParentDependencyKey(jobKey, false, parentKey, KEYS[1]) then
29
29
  rcall("HDEL", jobKey, "parentKey", "parent")
30
30
 
31
31
  return 0
@@ -303,7 +303,7 @@ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
303
303
  rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
304
304
  end
305
305
  end
306
- local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
306
+ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey)
307
307
  if parentKey then
308
308
  local parentDependenciesKey = parentKey .. ":dependencies"
309
309
  local result = rcall("SREM", parentDependenciesKey, jobKey)
@@ -316,11 +316,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
316
316
  if numRemovedElements == 1 then
317
317
  if hard then -- remove parent in same queue
318
318
  if parentPrefix == baseKey then
319
- removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
319
+ local parentDeduplicationId = rcall("HGET", parentKey, "deid")
320
+ removeParentDependencyKey(parentKey, hard, nil, baseKey)
320
321
  removeJobKeys(parentKey)
321
- if debounceId then
322
- rcall("DEL", parentPrefix .. "de:" .. debounceId)
323
- end
322
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
324
323
  else
325
324
  _moveParentToWait(parentPrefix, parentId)
326
325
  end
@@ -332,8 +331,7 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
332
331
  return true
333
332
  end
334
333
  else
335
- local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
336
- local missedParentKey = parentAttributes[1]
334
+ local missedParentKey = rcall("HGET", jobKey, "parentKey")
337
335
  if( (type(missedParentKey) == "string") and missedParentKey ~= ""
338
336
  and (rcall("EXISTS", missedParentKey) == 1)) then
339
337
  local parentDependenciesKey = missedParentKey .. ":dependencies"
@@ -347,11 +345,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
347
345
  if numRemovedElements == 1 then
348
346
  if hard then
349
347
  if parentPrefix == baseKey then
350
- removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
348
+ local parentDeduplicationId = rcall("HGET", missedParentKey, "deid")
349
+ removeParentDependencyKey(missedParentKey, hard, nil, baseKey)
351
350
  removeJobKeys(missedParentKey)
352
- if parentAttributes[2] then
353
- rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
354
- end
351
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
355
352
  else
356
353
  _moveParentToWait(parentPrefix, parentId)
357
354
  end
@@ -148,7 +148,7 @@ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
148
148
  rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
149
149
  end
150
150
  end
151
- local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
151
+ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey)
152
152
  if parentKey then
153
153
  local parentDependenciesKey = parentKey .. ":dependencies"
154
154
  local result = rcall("SREM", parentDependenciesKey, jobKey)
@@ -161,11 +161,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
161
161
  if numRemovedElements == 1 then
162
162
  if hard then -- remove parent in same queue
163
163
  if parentPrefix == baseKey then
164
- removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
164
+ local parentDeduplicationId = rcall("HGET", parentKey, "deid")
165
+ removeParentDependencyKey(parentKey, hard, nil, baseKey)
165
166
  removeJobKeys(parentKey)
166
- if debounceId then
167
- rcall("DEL", parentPrefix .. "de:" .. debounceId)
168
- end
167
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
169
168
  else
170
169
  _moveParentToWait(parentPrefix, parentId)
171
170
  end
@@ -177,8 +176,7 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
177
176
  return true
178
177
  end
179
178
  else
180
- local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
181
- local missedParentKey = parentAttributes[1]
179
+ local missedParentKey = rcall("HGET", jobKey, "parentKey")
182
180
  if( (type(missedParentKey) == "string") and missedParentKey ~= ""
183
181
  and (rcall("EXISTS", missedParentKey) == 1)) then
184
182
  local parentDependenciesKey = missedParentKey .. ":dependencies"
@@ -192,11 +190,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
192
190
  if numRemovedElements == 1 then
193
191
  if hard then
194
192
  if parentPrefix == baseKey then
195
- removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
193
+ local parentDeduplicationId = rcall("HGET", missedParentKey, "deid")
194
+ removeParentDependencyKey(missedParentKey, hard, nil, baseKey)
196
195
  removeJobKeys(missedParentKey)
197
- if parentAttributes[2] then
198
- rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
199
- end
196
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
200
197
  else
201
198
  _moveParentToWait(parentPrefix, parentId)
202
199
  end
@@ -120,7 +120,7 @@ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
120
120
  rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
121
121
  end
122
122
  end
123
- local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
123
+ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey)
124
124
  if parentKey then
125
125
  local parentDependenciesKey = parentKey .. ":dependencies"
126
126
  local result = rcall("SREM", parentDependenciesKey, jobKey)
@@ -133,11 +133,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
133
133
  if numRemovedElements == 1 then
134
134
  if hard then -- remove parent in same queue
135
135
  if parentPrefix == baseKey then
136
- removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
136
+ local parentDeduplicationId = rcall("HGET", parentKey, "deid")
137
+ removeParentDependencyKey(parentKey, hard, nil, baseKey)
137
138
  removeJobKeys(parentKey)
138
- if debounceId then
139
- rcall("DEL", parentPrefix .. "de:" .. debounceId)
140
- end
139
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
141
140
  else
142
141
  _moveParentToWait(parentPrefix, parentId)
143
142
  end
@@ -149,8 +148,7 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
149
148
  return true
150
149
  end
151
150
  else
152
- local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
153
- local missedParentKey = parentAttributes[1]
151
+ local missedParentKey = rcall("HGET", jobKey, "parentKey")
154
152
  if( (type(missedParentKey) == "string") and missedParentKey ~= ""
155
153
  and (rcall("EXISTS", missedParentKey) == 1)) then
156
154
  local parentDependenciesKey = missedParentKey .. ":dependencies"
@@ -164,11 +162,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
164
162
  if numRemovedElements == 1 then
165
163
  if hard then
166
164
  if parentPrefix == baseKey then
167
- removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
165
+ local parentDeduplicationId = rcall("HGET", missedParentKey, "deid")
166
+ removeParentDependencyKey(missedParentKey, hard, nil, baseKey)
168
167
  removeJobKeys(missedParentKey)
169
- if parentAttributes[2] then
170
- rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
171
- end
168
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
172
169
  else
173
170
  _moveParentToWait(parentPrefix, parentId)
174
171
  end
@@ -574,7 +574,7 @@ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
574
574
  rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
575
575
  end
576
576
  end
577
- local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
577
+ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey)
578
578
  if parentKey then
579
579
  local parentDependenciesKey = parentKey .. ":dependencies"
580
580
  local result = rcall("SREM", parentDependenciesKey, jobKey)
@@ -587,11 +587,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
587
587
  if numRemovedElements == 1 then
588
588
  if hard then -- remove parent in same queue
589
589
  if parentPrefix == baseKey then
590
- removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
590
+ local parentDeduplicationId = rcall("HGET", parentKey, "deid")
591
+ removeParentDependencyKey(parentKey, hard, nil, baseKey)
591
592
  removeJobKeys(parentKey)
592
- if debounceId then
593
- rcall("DEL", parentPrefix .. "de:" .. debounceId)
594
- end
593
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
595
594
  else
596
595
  _moveParentToWait(parentPrefix, parentId)
597
596
  end
@@ -603,8 +602,7 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
603
602
  return true
604
603
  end
605
604
  else
606
- local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
607
- local missedParentKey = parentAttributes[1]
605
+ local missedParentKey = rcall("HGET", jobKey, "parentKey")
608
606
  if( (type(missedParentKey) == "string") and missedParentKey ~= ""
609
607
  and (rcall("EXISTS", missedParentKey) == 1)) then
610
608
  local parentDependenciesKey = missedParentKey .. ":dependencies"
@@ -618,11 +616,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
618
616
  if numRemovedElements == 1 then
619
617
  if hard then
620
618
  if parentPrefix == baseKey then
621
- removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
619
+ local parentDeduplicationId = rcall("HGET", missedParentKey, "deid")
620
+ removeParentDependencyKey(missedParentKey, hard, nil, baseKey)
622
621
  removeJobKeys(missedParentKey)
623
- if parentAttributes[2] then
624
- rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
625
- end
622
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
626
623
  else
627
624
  _moveParentToWait(parentPrefix, parentId)
628
625
  end
@@ -998,7 +995,7 @@ if rcall("EXISTS", jobIdKey) == 1 then -- Make sure job exists
998
995
  -- TODO: when a child is removed when finished, result or failure in parent
999
996
  -- must not be deleted, those value references should be deleted when the parent
1000
997
  -- is deleted
1001
- removeParentDependencyKey(jobIdKey, false, parentKey, jobAttributes[3])
998
+ removeParentDependencyKey(jobIdKey, false, parentKey, prefix)
1002
999
  end
1003
1000
  end
1004
1001
  rcall("XADD", eventStreamKey, "*", "event", ARGV[5], "jobId", jobId, ARGV[3], ARGV[4], "prev", "active")
@@ -108,7 +108,7 @@ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
108
108
  rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
109
109
  end
110
110
  end
111
- local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
111
+ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey)
112
112
  if parentKey then
113
113
  local parentDependenciesKey = parentKey .. ":dependencies"
114
114
  local result = rcall("SREM", parentDependenciesKey, jobKey)
@@ -121,11 +121,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
121
121
  if numRemovedElements == 1 then
122
122
  if hard then -- remove parent in same queue
123
123
  if parentPrefix == baseKey then
124
- removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
124
+ local parentDeduplicationId = rcall("HGET", parentKey, "deid")
125
+ removeParentDependencyKey(parentKey, hard, nil, baseKey)
125
126
  removeJobKeys(parentKey)
126
- if debounceId then
127
- rcall("DEL", parentPrefix .. "de:" .. debounceId)
128
- end
127
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
129
128
  else
130
129
  _moveParentToWait(parentPrefix, parentId)
131
130
  end
@@ -137,8 +136,7 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
137
136
  return true
138
137
  end
139
138
  else
140
- local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
141
- local missedParentKey = parentAttributes[1]
139
+ local missedParentKey = rcall("HGET", jobKey, "parentKey")
142
140
  if( (type(missedParentKey) == "string") and missedParentKey ~= ""
143
141
  and (rcall("EXISTS", missedParentKey) == 1)) then
144
142
  local parentDependenciesKey = missedParentKey .. ":dependencies"
@@ -152,11 +150,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
152
150
  if numRemovedElements == 1 then
153
151
  if hard then
154
152
  if parentPrefix == baseKey then
155
- removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
153
+ local parentDeduplicationId = rcall("HGET", missedParentKey, "deid")
154
+ removeParentDependencyKey(missedParentKey, hard, nil, baseKey)
156
155
  removeJobKeys(missedParentKey)
157
- if parentAttributes[2] then
158
- rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
159
- end
156
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
160
157
  else
161
158
  _moveParentToWait(parentPrefix, parentId)
162
159
  end
@@ -66,6 +66,23 @@ local function isQueuePausedOrMaxed(queueMetaKey, activeKey)
66
66
  end
67
67
  return false
68
68
  end
69
+ --[[
70
+ Function to remove deduplication key if needed
71
+ when a job is being removed.
72
+ ]]
73
+ local function removeDeduplicationKeyIfNeededOnRemoval(prefixKey,
74
+ jobId, deduplicationId)
75
+ if deduplicationId then
76
+ local deduplicationKey = prefixKey .. "de:" .. deduplicationId
77
+ local currentJobId = rcall('GET', deduplicationKey)
78
+ if currentJobId and currentJobId == jobId then
79
+ rcall("DEL", deduplicationKey)
80
+ -- Also clean up any pending dedup-next data for this dedup ID
81
+ rcall("DEL", prefixKey .. "dn:" .. deduplicationId)
82
+ return 1
83
+ end
84
+ end
85
+ end
69
86
  --[[
70
87
  Function to remove job keys.
71
88
  ]]
@@ -82,7 +99,7 @@ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
82
99
  rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
83
100
  end
84
101
  end
85
- local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
102
+ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey)
86
103
  if parentKey then
87
104
  local parentDependenciesKey = parentKey .. ":dependencies"
88
105
  local result = rcall("SREM", parentDependenciesKey, jobKey)
@@ -95,11 +112,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
95
112
  if numRemovedElements == 1 then
96
113
  if hard then -- remove parent in same queue
97
114
  if parentPrefix == baseKey then
98
- removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
115
+ local parentDeduplicationId = rcall("HGET", parentKey, "deid")
116
+ removeParentDependencyKey(parentKey, hard, nil, baseKey)
99
117
  removeJobKeys(parentKey)
100
- if debounceId then
101
- rcall("DEL", parentPrefix .. "de:" .. debounceId)
102
- end
118
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
103
119
  else
104
120
  _moveParentToWait(parentPrefix, parentId)
105
121
  end
@@ -111,8 +127,7 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
111
127
  return true
112
128
  end
113
129
  else
114
- local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
115
- local missedParentKey = parentAttributes[1]
130
+ local missedParentKey = rcall("HGET", jobKey, "parentKey")
116
131
  if( (type(missedParentKey) == "string") and missedParentKey ~= ""
117
132
  and (rcall("EXISTS", missedParentKey) == 1)) then
118
133
  local parentDependenciesKey = missedParentKey .. ":dependencies"
@@ -126,11 +141,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
126
141
  if numRemovedElements == 1 then
127
142
  if hard then
128
143
  if parentPrefix == baseKey then
129
- removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
144
+ local parentDeduplicationId = rcall("HGET", missedParentKey, "deid")
145
+ removeParentDependencyKey(missedParentKey, hard, nil, baseKey)
130
146
  removeJobKeys(missedParentKey)
131
- if parentAttributes[2] then
132
- rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
133
- end
147
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
134
148
  else
135
149
  _moveParentToWait(parentPrefix, parentId)
136
150
  end
@@ -147,7 +161,7 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
147
161
  end
148
162
  if rcall("EXISTS", jobKey) ~= 1 then return -1 end
149
163
  if rcall("EXISTS", parentKey) ~= 1 then return -5 end
150
- if removeParentDependencyKey(jobKey, false, parentKey, KEYS[1], nil) then
164
+ if removeParentDependencyKey(jobKey, false, parentKey, KEYS[1]) then
151
165
  rcall("HDEL", jobKey, "parentKey", "parent")
152
166
  return 0
153
167
  else
@@ -192,7 +192,7 @@ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
192
192
  rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
193
193
  end
194
194
  end
195
- local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
195
+ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey)
196
196
  if parentKey then
197
197
  local parentDependenciesKey = parentKey .. ":dependencies"
198
198
  local result = rcall("SREM", parentDependenciesKey, jobKey)
@@ -205,11 +205,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
205
205
  if numRemovedElements == 1 then
206
206
  if hard then -- remove parent in same queue
207
207
  if parentPrefix == baseKey then
208
- removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
208
+ local parentDeduplicationId = rcall("HGET", parentKey, "deid")
209
+ removeParentDependencyKey(parentKey, hard, nil, baseKey)
209
210
  removeJobKeys(parentKey)
210
- if debounceId then
211
- rcall("DEL", parentPrefix .. "de:" .. debounceId)
212
- end
211
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
213
212
  else
214
213
  _moveParentToWait(parentPrefix, parentId)
215
214
  end
@@ -221,8 +220,7 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
221
220
  return true
222
221
  end
223
222
  else
224
- local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
225
- local missedParentKey = parentAttributes[1]
223
+ local missedParentKey = rcall("HGET", jobKey, "parentKey")
226
224
  if( (type(missedParentKey) == "string") and missedParentKey ~= ""
227
225
  and (rcall("EXISTS", missedParentKey) == 1)) then
228
226
  local parentDependenciesKey = missedParentKey .. ":dependencies"
@@ -236,11 +234,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
236
234
  if numRemovedElements == 1 then
237
235
  if hard then
238
236
  if parentPrefix == baseKey then
239
- removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
237
+ local parentDeduplicationId = rcall("HGET", missedParentKey, "deid")
238
+ removeParentDependencyKey(missedParentKey, hard, nil, baseKey)
240
239
  removeJobKeys(missedParentKey)
241
- if parentAttributes[2] then
242
- rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
243
- end
240
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
244
241
  else
245
242
  _moveParentToWait(parentPrefix, parentId)
246
243
  end
@@ -160,7 +160,7 @@ local function _moveParentToWait(parentPrefix, parentId, emitEvent)
160
160
  rcall("XADD", parentEventStream, "*", "event", "waiting", "jobId", parentId, "prev", "waiting-children")
161
161
  end
162
162
  end
163
- local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debounceId)
163
+ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey)
164
164
  if parentKey then
165
165
  local parentDependenciesKey = parentKey .. ":dependencies"
166
166
  local result = rcall("SREM", parentDependenciesKey, jobKey)
@@ -173,11 +173,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
173
173
  if numRemovedElements == 1 then
174
174
  if hard then -- remove parent in same queue
175
175
  if parentPrefix == baseKey then
176
- removeParentDependencyKey(parentKey, hard, nil, baseKey, nil)
176
+ local parentDeduplicationId = rcall("HGET", parentKey, "deid")
177
+ removeParentDependencyKey(parentKey, hard, nil, baseKey)
177
178
  removeJobKeys(parentKey)
178
- if debounceId then
179
- rcall("DEL", parentPrefix .. "de:" .. debounceId)
180
- end
179
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
181
180
  else
182
181
  _moveParentToWait(parentPrefix, parentId)
183
182
  end
@@ -189,8 +188,7 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
189
188
  return true
190
189
  end
191
190
  else
192
- local parentAttributes = rcall("HMGET", jobKey, "parentKey", "deid")
193
- local missedParentKey = parentAttributes[1]
191
+ local missedParentKey = rcall("HGET", jobKey, "parentKey")
194
192
  if( (type(missedParentKey) == "string") and missedParentKey ~= ""
195
193
  and (rcall("EXISTS", missedParentKey) == 1)) then
196
194
  local parentDependenciesKey = missedParentKey .. ":dependencies"
@@ -204,11 +202,10 @@ local function removeParentDependencyKey(jobKey, hard, parentKey, baseKey, debou
204
202
  if numRemovedElements == 1 then
205
203
  if hard then
206
204
  if parentPrefix == baseKey then
207
- removeParentDependencyKey(missedParentKey, hard, nil, baseKey, nil)
205
+ local parentDeduplicationId = rcall("HGET", missedParentKey, "deid")
206
+ removeParentDependencyKey(missedParentKey, hard, nil, baseKey)
208
207
  removeJobKeys(missedParentKey)
209
- if parentAttributes[2] then
210
- rcall("DEL", parentPrefix .. "de:" .. parentAttributes[2])
211
- end
208
+ removeDeduplicationKeyIfNeededOnRemoval(parentPrefix, parentId, parentDeduplicationId)
212
209
  else
213
210
  _moveParentToWait(parentPrefix, parentId)
214
211
  end