qdone 2.0.36-alpha → 2.0.38-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.
@@ -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;
@@ -212,6 +209,7 @@ exports.dedupShouldEnqueueMulti = dedupShouldEnqueueMulti;
212
209
  * @returns {Number} 1 if a cache key was deleted, otherwise 0
213
210
  */
214
211
  async function dedupSuccessfullyProcessed(message, opt) {
212
+ debug({ dedupSuccessfullyProcessed: { message, opt } });
215
213
  const client = (0, cache_js_1.getCacheClient)(opt);
216
214
  const dedupId = message?.MessageAttributes?.QdoneDeduplicationId?.StringValue;
217
215
  if (dedupId) {
@@ -57,7 +57,7 @@ function validateInteger(opt, name) {
57
57
  return parsed;
58
58
  }
59
59
  function validateMessageOptions(messageOptions) {
60
- const validKeys = ['deduplicaitonId', 'groupId'];
60
+ const validKeys = ['deduplicationId', 'groupId'];
61
61
  if (typeof messageOptions === 'object' &&
62
62
  !Array.isArray(messageOptions) &&
63
63
  messageOptions !== null) {
@@ -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 = await (0, dedup_js_1.dedupShouldEnqueueMulti)(params.Entries, opt);
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).map(({ m }) => m);
278
280
  if (!params.Entries.length)
279
281
  return;
280
282
  }
@@ -216,10 +216,10 @@ class JobExecutor {
216
216
  else if (!this.opt.disableLog) {
217
217
  console.log(JSON.stringify({ event: 'DELETE_MESSAGES', timestamp: start, count, qrl }));
218
218
  }
219
+ // Mark batch as processed for dedup
220
+ await Promise.all(result.Successful.map(e => (0, dedup_js_1.dedupSuccessfullyProcessed)(this.jobsByMessageId[e.Id], this.opt)));
219
221
  }
220
222
  debug('DeleteMessageBatch returned', result);
221
- // Mark batch as processed for dedup
222
- await (0, dedup_js_1.dedupSuccessfullyProcessedMulti)(entries.map(e => this.jobsByMessageId[e.Id]), this.opt);
223
223
  // TODO Sentry
224
224
  }
225
225
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qdone",
3
- "version": "2.0.36-alpha",
3
+ "version": "2.0.38-alpha",
4
4
  "description": "A distributed scheduler for SQS",
5
5
  "type": "module",
6
6
  "main": "./index.js",
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
@@ -206,6 +202,7 @@ export async function dedupShouldEnqueueMulti (messages, opt) {
206
202
  * @returns {Number} 1 if a cache key was deleted, otherwise 0
207
203
  */
208
204
  export async function dedupSuccessfullyProcessed (message, opt) {
205
+ debug({ dedupSuccessfullyProcessed: { message, opt } })
209
206
  const client = getCacheClient(opt)
210
207
  const dedupId = message?.MessageAttributes?.QdoneDeduplicationId?.StringValue
211
208
  if (dedupId) {
@@ -230,7 +227,7 @@ export async function dedupSuccessfullyProcessed (message, opt) {
230
227
  * @returns {Number} number of deleted keys
231
228
  */
232
229
  export async function dedupSuccessfullyProcessedMulti (messages, opt) {
233
- debug({ messages, dedupSuccessfullyProcessedMulti: { messages, opt }})
230
+ debug({ messages, dedupSuccessfullyProcessedMulti: { messages, opt } })
234
231
  const cacheKeys = []
235
232
  for (const message of messages) {
236
233
  const dedupId = message?.MessageAttributes?.QdoneDeduplicationId?.StringValue
@@ -239,7 +236,7 @@ export async function dedupSuccessfullyProcessedMulti (messages, opt) {
239
236
  cacheKeys.push(cacheKey)
240
237
  }
241
238
  }
242
- debug({ dedupSuccessfullyProcessedMulti: { cacheKeys }})
239
+ debug({ dedupSuccessfullyProcessedMulti: { cacheKeys } })
243
240
  if (cacheKeys.length) {
244
241
  const numDeleted = await getCacheClient(opt).del(cacheKeys)
245
242
  // 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 = ['deduplicaitonId', 'groupId']
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 = await dedupShouldEnqueueMulti(params.Entries, opt)
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).map(({ m }) => m)
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 { dedupSuccessfullyProcessedMulti } from '../dedup.js'
11
+ import { dedupSuccessfullyProcessed } from '../dedup.js'
12
12
  import { getSQSClient } from '../sqs.js'
13
13
 
14
14
  const debug = Debug('qdone:jobExecutor')
@@ -220,11 +220,16 @@ export class JobExecutor {
220
220
  } else if (!this.opt.disableLog) {
221
221
  console.log(JSON.stringify({ event: 'DELETE_MESSAGES', timestamp: start, count, qrl }))
222
222
  }
223
+
224
+ // Mark batch as processed for dedup
225
+ await Promise.all(
226
+ result.Successful.map(
227
+ e => dedupSuccessfullyProcessed(this.jobsByMessageId[e.Id], this.opt)
228
+ )
229
+ )
223
230
  }
224
231
  debug('DeleteMessageBatch returned', result)
225
232
 
226
- // Mark batch as processed for dedup
227
- await dedupSuccessfullyProcessedMulti(entries.map(e => this.jobsByMessageId[e.Id]), this.opt)
228
233
 
229
234
  // TODO Sentry
230
235
  }