qdone 2.0.36-alpha → 2.0.37-alpha
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.
- package/commonjs/src/dedup.js +0 -3
- package/commonjs/src/defaults.js +1 -1
- package/commonjs/src/enqueue.js +3 -1
- package/commonjs/src/scheduler/jobExecutor.js +1 -1
- package/package.json +1 -1
- package/src/dedup.js +6 -10
- package/src/defaults.js +1 -1
- package/src/enqueue.js +3 -2
- package/src/scheduler/jobExecutor.js +2 -2
- package/npm-shrinkwrap.json +0 -16000
package/commonjs/src/dedup.js
CHANGED
|
@@ -176,9 +176,6 @@ async function dedupShouldEnqueueMulti(messages, opt) {
|
|
|
176
176
|
}
|
|
177
177
|
const responses = await incrPipeline.exec();
|
|
178
178
|
debug({ dedupShouldEnqueueMulti: { messages, responses } });
|
|
179
|
-
// Figure out dedup period
|
|
180
|
-
const minDedupPeriod = 6 * 60;
|
|
181
|
-
const dedupPeriod = Math.min(opt.dedupPeriod, minDedupPeriod);
|
|
182
179
|
// Interpret responses and expire keys for races we won
|
|
183
180
|
const expirePipeline = (0, cache_js_1.getCacheClient)(opt).pipeline();
|
|
184
181
|
const statsPipeline = opt.dedupStats ? (0, cache_js_1.getCacheClient)(opt).pipeline() : undefined;
|
package/commonjs/src/defaults.js
CHANGED
|
@@ -57,7 +57,7 @@ function validateInteger(opt, name) {
|
|
|
57
57
|
return parsed;
|
|
58
58
|
}
|
|
59
59
|
function validateMessageOptions(messageOptions) {
|
|
60
|
-
const validKeys = ['
|
|
60
|
+
const validKeys = ['deduplicationId', 'groupId'];
|
|
61
61
|
if (typeof messageOptions === 'object' &&
|
|
62
62
|
!Array.isArray(messageOptions) &&
|
|
63
63
|
messageOptions !== null) {
|
package/commonjs/src/enqueue.js
CHANGED
|
@@ -274,7 +274,9 @@ async function sendMessageBatch(qrl, messages, opt) {
|
|
|
274
274
|
debug({ params });
|
|
275
275
|
// See which messages we even have to send
|
|
276
276
|
if (opt.externalDedup) {
|
|
277
|
-
params.Entries
|
|
277
|
+
const promises = params.Entries.map(async (m) => ({ m, shouldEnqueue: await (0, dedup_js_1.dedupShouldEnqueue)(m, opt) }));
|
|
278
|
+
const results = await Promise.all(promises);
|
|
279
|
+
params.Entries = results.filter(({ shouldEnqueue }) => shouldEnqueue);
|
|
278
280
|
if (!params.Entries.length)
|
|
279
281
|
return;
|
|
280
282
|
}
|
|
@@ -219,7 +219,7 @@ class JobExecutor {
|
|
|
219
219
|
}
|
|
220
220
|
debug('DeleteMessageBatch returned', result);
|
|
221
221
|
// Mark batch as processed for dedup
|
|
222
|
-
await
|
|
222
|
+
await Promise.all(entries.map(e => (0, dedup_js_1.dedupSuccessfullyProcessed)(this.jobsByMessageId[e.Id], this.opt)));
|
|
223
223
|
// TODO Sentry
|
|
224
224
|
}
|
|
225
225
|
}
|
package/package.json
CHANGED
package/src/dedup.js
CHANGED
|
@@ -112,9 +112,9 @@ export async function statMaintenance (opt) {
|
|
|
112
112
|
const now = new Date().getTime()
|
|
113
113
|
|
|
114
114
|
// Grab a batch of expired keys
|
|
115
|
-
debug({ statMaintenance: { aboutToGo: true, expirationSet }})
|
|
115
|
+
debug({ statMaintenance: { aboutToGo: true, expirationSet } })
|
|
116
116
|
const expiredStats = await client.zrange(expirationSet, '-inf', now, 'BYSCORE')
|
|
117
|
-
debug({ statMaintenance: { expiredStats }})
|
|
117
|
+
debug({ statMaintenance: { expiredStats } })
|
|
118
118
|
|
|
119
119
|
// And remove them from indexes, main storage
|
|
120
120
|
if (expiredStats.length) {
|
|
@@ -122,7 +122,7 @@ export async function statMaintenance (opt) {
|
|
|
122
122
|
.zrem(expirationSet, expiredStats)
|
|
123
123
|
.zrem(duplicateSet, expiredStats)
|
|
124
124
|
.exec()
|
|
125
|
-
debug({ statMaintenance: { result }})
|
|
125
|
+
debug({ statMaintenance: { result } })
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
|
|
@@ -159,7 +159,7 @@ export async function dedupShouldEnqueue (message, opt) {
|
|
|
159
159
|
* @returns {Array[Object]} an array of messages that can be safely enqueued. Could be empty.
|
|
160
160
|
*/
|
|
161
161
|
export async function dedupShouldEnqueueMulti (messages, opt) {
|
|
162
|
-
debug({ dedupShouldEnqueueMulti: { messages, opt }})
|
|
162
|
+
debug({ dedupShouldEnqueueMulti: { messages, opt } })
|
|
163
163
|
const expireAt = new Date().getTime() + opt.dedupPeriod
|
|
164
164
|
// Increment all
|
|
165
165
|
const incrPipeline = getCacheClient(opt).pipeline()
|
|
@@ -171,10 +171,6 @@ export async function dedupShouldEnqueueMulti (messages, opt) {
|
|
|
171
171
|
const responses = await incrPipeline.exec()
|
|
172
172
|
debug({ dedupShouldEnqueueMulti: { messages, responses } })
|
|
173
173
|
|
|
174
|
-
// Figure out dedup period
|
|
175
|
-
const minDedupPeriod = 6 * 60
|
|
176
|
-
const dedupPeriod = Math.min(opt.dedupPeriod, minDedupPeriod)
|
|
177
|
-
|
|
178
174
|
// Interpret responses and expire keys for races we won
|
|
179
175
|
const expirePipeline = getCacheClient(opt).pipeline()
|
|
180
176
|
const statsPipeline = opt.dedupStats ? getCacheClient(opt).pipeline() : undefined
|
|
@@ -230,7 +226,7 @@ export async function dedupSuccessfullyProcessed (message, opt) {
|
|
|
230
226
|
* @returns {Number} number of deleted keys
|
|
231
227
|
*/
|
|
232
228
|
export async function dedupSuccessfullyProcessedMulti (messages, opt) {
|
|
233
|
-
debug({ messages, dedupSuccessfullyProcessedMulti: { messages, opt }})
|
|
229
|
+
debug({ messages, dedupSuccessfullyProcessedMulti: { messages, opt } })
|
|
234
230
|
const cacheKeys = []
|
|
235
231
|
for (const message of messages) {
|
|
236
232
|
const dedupId = message?.MessageAttributes?.QdoneDeduplicationId?.StringValue
|
|
@@ -239,7 +235,7 @@ export async function dedupSuccessfullyProcessedMulti (messages, opt) {
|
|
|
239
235
|
cacheKeys.push(cacheKey)
|
|
240
236
|
}
|
|
241
237
|
}
|
|
242
|
-
debug({ dedupSuccessfullyProcessedMulti: { cacheKeys }})
|
|
238
|
+
debug({ dedupSuccessfullyProcessedMulti: { cacheKeys } })
|
|
243
239
|
if (cacheKeys.length) {
|
|
244
240
|
const numDeleted = await getCacheClient(opt).del(cacheKeys)
|
|
245
241
|
// const numDeleted = results.map(([, val]) => val).reduce((a, b) => a + b, 0)
|
package/src/defaults.js
CHANGED
|
@@ -60,7 +60,7 @@ function validateInteger (opt, name) {
|
|
|
60
60
|
}
|
|
61
61
|
|
|
62
62
|
export function validateMessageOptions (messageOptions) {
|
|
63
|
-
const validKeys = ['
|
|
63
|
+
const validKeys = ['deduplicationId', 'groupId']
|
|
64
64
|
if (typeof messageOptions === 'object' &&
|
|
65
65
|
!Array.isArray(messageOptions) &&
|
|
66
66
|
messageOptions !== null) {
|
package/src/enqueue.js
CHANGED
|
@@ -23,7 +23,6 @@ import { getSQSClient } from './sqs.js'
|
|
|
23
23
|
import {
|
|
24
24
|
addDedupParamsToMessage,
|
|
25
25
|
dedupShouldEnqueue,
|
|
26
|
-
dedupShouldEnqueueMulti,
|
|
27
26
|
dedupSuccessfullyProcessed
|
|
28
27
|
} from './dedup.js'
|
|
29
28
|
import { getOptionsWithDefaults, validateMessageOptions } from './defaults.js'
|
|
@@ -274,7 +273,9 @@ export async function sendMessageBatch (qrl, messages, opt) {
|
|
|
274
273
|
|
|
275
274
|
// See which messages we even have to send
|
|
276
275
|
if (opt.externalDedup) {
|
|
277
|
-
params.Entries
|
|
276
|
+
const promises = params.Entries.map(async m => ({ m, shouldEnqueue: await dedupShouldEnqueue(m, opt) }))
|
|
277
|
+
const results = await Promise.all(promises)
|
|
278
|
+
params.Entries = results.filter(({ shouldEnqueue }) => shouldEnqueue)
|
|
278
279
|
if (!params.Entries.length) return
|
|
279
280
|
}
|
|
280
281
|
|
|
@@ -8,7 +8,7 @@ import { ChangeMessageVisibilityBatchCommand, DeleteMessageBatchCommand } from '
|
|
|
8
8
|
import chalk from 'chalk'
|
|
9
9
|
import Debug from 'debug'
|
|
10
10
|
|
|
11
|
-
import {
|
|
11
|
+
import { dedupSuccessfullyProcessed } from '../dedup.js'
|
|
12
12
|
import { getSQSClient } from '../sqs.js'
|
|
13
13
|
|
|
14
14
|
const debug = Debug('qdone:jobExecutor')
|
|
@@ -224,7 +224,7 @@ export class JobExecutor {
|
|
|
224
224
|
debug('DeleteMessageBatch returned', result)
|
|
225
225
|
|
|
226
226
|
// Mark batch as processed for dedup
|
|
227
|
-
await
|
|
227
|
+
await Promise.all(entries.map(e => dedupSuccessfullyProcessed(this.jobsByMessageId[e.Id], this.opt)))
|
|
228
228
|
|
|
229
229
|
// TODO Sentry
|
|
230
230
|
}
|