@flowcore/data-pump 0.14.0 → 0.15.0
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.15.0](https://github.com/flowcore-io/data-pump/compare/v0.14.0...v0.15.0) (2025-06-03)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **data-pump:** :sparkles: add acknowledgment timeout scaling and timeout management ([17ea18d](https://github.com/flowcore-io/data-pump/commit/17ea18d6cef86ad73a77158a1008ce353e3471bb))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **data-pump:** :art: reverted concurrency changes ([0f0b29c](https://github.com/flowcore-io/data-pump/commit/0f0b29ce5a807cd5bf0e6a44798310ee409adab1))
|
|
14
|
+
* **data-pump:** :art: update timeoutId type to use ReturnType of setTimeout ([132aba2](https://github.com/flowcore-io/data-pump/commit/132aba2153e70b8532fab3cfc53816e2d9450c21))
|
|
15
|
+
* **deno:** :art: update deno.lock version and format deno.json ([9bf22c7](https://github.com/flowcore-io/data-pump/commit/9bf22c767f3e2c3c413386d38e4f2d60cdd586f8))
|
|
16
|
+
|
|
3
17
|
## [0.14.0](https://github.com/flowcore-io/data-pump/compare/v0.13.0...v0.14.0) (2025-06-03)
|
|
4
18
|
|
|
5
19
|
|
package/README.md
CHANGED
|
@@ -39,28 +39,3 @@ await dataPump.start((error?: Error) => {
|
|
|
39
39
|
console.log("Datapump ended with: ", error)
|
|
40
40
|
})
|
|
41
41
|
```
|
|
42
|
-
|
|
43
|
-
## Configuration
|
|
44
|
-
|
|
45
|
-
### Concurrency and Acknowledgment Timeout
|
|
46
|
-
|
|
47
|
-
When using higher concurrency values, the data pump automatically scales the acknowledgment timeout to prevent events
|
|
48
|
-
from being prematurely failed due to processing time. The default acknowledgment timeout is calculated as:
|
|
49
|
-
|
|
50
|
-
```ts
|
|
51
|
-
const defaultAckTimeout = Math.max(10_000, concurrency * 2_000) // At least 10s, scale with concurrency
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
For example:
|
|
55
|
-
|
|
56
|
-
- `concurrency: 1` → `achknowledgeTimeoutMs: 10_000` (10 seconds)
|
|
57
|
-
- `concurrency: 10` → `achknowledgeTimeoutMs: 20_000` (20 seconds)
|
|
58
|
-
- `concurrency: 50` → `achknowledgeTimeoutMs: 100_000` (100 seconds)
|
|
59
|
-
|
|
60
|
-
You can override this by explicitly setting `achknowledgeTimeoutMs` in the options.
|
|
61
|
-
|
|
62
|
-
### Important Notes
|
|
63
|
-
|
|
64
|
-
- When using high concurrency, ensure your `achknowledgeTimeoutMs` is sufficient for your processing time
|
|
65
|
-
- Events that exceed `maxRedeliveryCount` (default: 3) will be permanently removed from the buffer
|
|
66
|
-
- The buffer management has been improved to prevent timeout race conditions with high concurrency
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-pump.d.ts","sourceRoot":"","sources":["../../src/data-pump/data-pump.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAA;AAGnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAGrD,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,EACrB,4BAA4B,EAC5B,cAAc,EACf,MAAM,YAAY,CAAA;AAEnB,UAAU,mCAAmC;IAC3C,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,UAAU,wCAAwC;IAChD,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,UAAU,qCAAqC;IAC7C,IAAI,EAAE,QAAQ,CAAA;IACd;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,+BA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K,CAAC,EAAE,KAAK,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IA2C9D,OAAO,CAAC,KAAK,EAAE,qBAAqB,EAAE,MAAM,CAAC,EAAE,IAAI,GAAG,IAAI,GAAG,IAAI;IAQjE,IAAI,CAAC,SAAS,UAAQ,GAAG,IAAI;IAWpC,OAAO,CAAC,WAAW;YAaL,IAAI;IAmFL,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAqCjD,WAAW,CAAC,QAAQ,EAAE,MAAM,EAAE;IA0B9B,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE;YA4BtB,MAAM;YAiDN,WAAW;IAiBzB,OAAO,CAAC,mBAAmB;IA4D3B,OAAO,CAAC,iBAAiB;IA0CzB,OAAO,CAAC,YAAY,CAAC,CAAY;YACnB,aAAa;IAO3B,OAAO,CAAC,qBAAqB,CAAC,CAAY;YAC5B,sBAAsB;IAOpC,OAAO,CAAC,iBAAiB,CAAC,CAAY;YACxB,kBAAkB;CAWjC"}
|
|
@@ -129,14 +129,11 @@ export class FlowcoreDataPump {
|
|
|
129
129
|
directMode: options.directMode,
|
|
130
130
|
noTranslation: options.noTranslation,
|
|
131
131
|
});
|
|
132
|
-
// Calculate acknowledgment timeout based on concurrency if not explicitly set
|
|
133
|
-
const concurrency = options.processor?.concurrency ?? 1;
|
|
134
|
-
const defaultAckTimeout = Math.max(10_000, concurrency * 2_000); // At least 10s, scale with concurrency
|
|
135
132
|
return new FlowcoreDataPump(dataSource, notifier, options.stateManager, {
|
|
136
133
|
bufferSize: options.bufferSize ?? 1000,
|
|
137
134
|
bufferThreshold: Math.ceil((options.bufferSize ?? 1000) * 0.1),
|
|
138
135
|
maxRedeliveryCount: options.maxRedeliveryCount ?? 3,
|
|
139
|
-
achknowledgeTimeoutMs: options.achknowledgeTimeoutMs ??
|
|
136
|
+
achknowledgeTimeoutMs: options.achknowledgeTimeoutMs ?? 5_000,
|
|
140
137
|
includeSensitiveData: options.includeSensitiveData ?? false,
|
|
141
138
|
processor: options.processor,
|
|
142
139
|
stopAt: options.stopAt,
|
|
@@ -273,14 +270,12 @@ export class FlowcoreDataPump {
|
|
|
273
270
|
}
|
|
274
271
|
const events = [];
|
|
275
272
|
const deliveryId = crypto.randomUUID();
|
|
276
|
-
const reservedBufferItems = [];
|
|
277
273
|
for (const event of this.buffer) {
|
|
278
274
|
if (event.status === "open") {
|
|
279
275
|
event.status = "reserved";
|
|
280
276
|
event.deliveryId = deliveryId;
|
|
281
277
|
event.deliveryCount++;
|
|
282
278
|
events.push(event.event);
|
|
283
|
-
reservedBufferItems.push(event);
|
|
284
279
|
this.incMetricsCounter("pulled", event.event.eventType, JSON.stringify(event.event).length);
|
|
285
280
|
if (events.length === amount) {
|
|
286
281
|
break;
|
|
@@ -292,13 +287,9 @@ export class FlowcoreDataPump {
|
|
|
292
287
|
return this.reserve(amount);
|
|
293
288
|
}
|
|
294
289
|
this.updateMetricsGauges();
|
|
295
|
-
|
|
290
|
+
setTimeout(() => {
|
|
296
291
|
this.reOpen(events.map((event) => event.eventId), deliveryId);
|
|
297
292
|
}, this.options.achknowledgeTimeoutMs);
|
|
298
|
-
// Store timeout ID in all reserved items so we can clear it on acknowledgment
|
|
299
|
-
for (const item of reservedBufferItems) {
|
|
300
|
-
item.timeoutId = timeoutId;
|
|
301
|
-
}
|
|
302
293
|
return events;
|
|
303
294
|
}
|
|
304
295
|
async acknowledge(eventIds) {
|
|
@@ -306,22 +297,13 @@ export class FlowcoreDataPump {
|
|
|
306
297
|
return;
|
|
307
298
|
}
|
|
308
299
|
const lastEventInBuffer = this.buffer[this.buffer.length - 1];
|
|
309
|
-
const acknowledgedTimeoutIds = new Set();
|
|
310
300
|
this.buffer = this.buffer.filter((event) => {
|
|
311
301
|
if (eventIds.includes(event.event.eventId)) {
|
|
312
302
|
this.incMetricsCounter("acknowledged", event.event.eventType, 1);
|
|
313
|
-
// Collect timeout IDs to clear them
|
|
314
|
-
if (event.timeoutId !== undefined) {
|
|
315
|
-
acknowledgedTimeoutIds.add(event.timeoutId);
|
|
316
|
-
}
|
|
317
303
|
return false;
|
|
318
304
|
}
|
|
319
305
|
return true;
|
|
320
306
|
});
|
|
321
|
-
// Clear timeouts for acknowledged events to prevent unnecessary reOpen calls
|
|
322
|
-
for (const timeoutId of acknowledgedTimeoutIds) {
|
|
323
|
-
clearTimeout(timeoutId);
|
|
324
|
-
}
|
|
325
307
|
if (this.buffer.length <= this.options.bufferSize - this.options.bufferThreshold) {
|
|
326
308
|
this.waiterBufferThreshold?.();
|
|
327
309
|
}
|
|
@@ -337,23 +319,14 @@ export class FlowcoreDataPump {
|
|
|
337
319
|
}
|
|
338
320
|
const lastEventInBuffer = this.buffer[this.buffer.length - 1];
|
|
339
321
|
const failedEvents = [];
|
|
340
|
-
const failedTimeoutIds = new Set();
|
|
341
322
|
this.buffer = this.buffer.filter((event) => {
|
|
342
323
|
if (eventIds.includes(event.event.eventId)) {
|
|
343
324
|
this.incMetricsCounter("failed", event.event.eventType, 1);
|
|
344
325
|
failedEvents.push(event.event);
|
|
345
|
-
// Collect timeout IDs to clear them
|
|
346
|
-
if (event.timeoutId !== undefined) {
|
|
347
|
-
failedTimeoutIds.add(event.timeoutId);
|
|
348
|
-
}
|
|
349
326
|
return false;
|
|
350
327
|
}
|
|
351
328
|
return true;
|
|
352
329
|
});
|
|
353
|
-
// Clear timeouts for failed events
|
|
354
|
-
for (const timeoutId of failedTimeoutIds) {
|
|
355
|
-
clearTimeout(timeoutId);
|
|
356
|
-
}
|
|
357
330
|
this.logger?.info(`Failed ${failedEvents.length} events`);
|
|
358
331
|
void this.options.processor?.failedHandler?.(failedEvents);
|
|
359
332
|
if (this.buffer.length <= this.options.bufferSize - this.options.bufferThreshold) {
|
|
@@ -380,7 +353,6 @@ export class FlowcoreDataPump {
|
|
|
380
353
|
}
|
|
381
354
|
event.status = "open";
|
|
382
355
|
event.deliveryId = undefined;
|
|
383
|
-
event.timeoutId = undefined;
|
|
384
356
|
reopenedEvents.push(event.event);
|
|
385
357
|
return true;
|
|
386
358
|
});
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-pump.d.ts","sourceRoot":"","sources":["../../src/data-pump/data-pump.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAA;AAGnF,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAA;AAGrD,OAAO,KAAK,EACV,oBAAoB,EACpB,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,EACrB,4BAA4B,EAC5B,cAAc,EACf,MAAM,YAAY,CAAA;AAEnB,UAAU,mCAAmC;IAC3C,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,EAAE,CAAA;CAClB;AAED,UAAU,wCAAwC;IAChD,IAAI,EAAE,WAAW,CAAA;CAClB;AAED,UAAU,qCAAqC;IAC7C,IAAI,EAAE,QAAQ,CAAA;IACd;;OAEG;IACH,UAAU,EAAE,MAAM,CAAA;CACnB;AAED,KAAK,+BAA+B,GAChC,mCAAmC,GACnC,wCAAwC,GACxC,qCAAqC,CAAA;AAEzC,MAAM,WAAW,uBAAuB;IACtC,IAAI,EAAE,oBAAoB,CAAA;IAC1B,UAAU,EAAE,0BAA0B,CAAA;IACtC,YAAY,EAAE,4BAA4B,CAAA;IAC1C,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAA;IAC3B,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,oBAAoB,CAAC,EAAE,OAAO,CAAA;IAC9B,SAAS,CAAC,EAAE,yBAAyB,CAAA;IACrC,QAAQ,CAAC,EAAE,+BAA+B,CAAA;IAC1C,MAAM,CAAC,EAAE,cAAc,CAAA;IACvB,MAAM,CAAC,EAAE,IAAI,CAAA;IACb,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,aAAa,CAAC,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AO3B,OAAO,CAAC,qBAAqB,CAAC,CAAY;YAC5B,sBAAsB;IAOpC,OAAO,CAAC,iBAAiB,CAAC,CAAY;YACxB,kBAAkB;CAWjC"}
|
|
@@ -132,14 +132,11 @@ class FlowcoreDataPump {
|
|
|
132
132
|
directMode: options.directMode,
|
|
133
133
|
noTranslation: options.noTranslation,
|
|
134
134
|
});
|
|
135
|
-
// Calculate acknowledgment timeout based on concurrency if not explicitly set
|
|
136
|
-
const concurrency = options.processor?.concurrency ?? 1;
|
|
137
|
-
const defaultAckTimeout = Math.max(10_000, concurrency * 2_000); // At least 10s, scale with concurrency
|
|
138
135
|
return new FlowcoreDataPump(dataSource, notifier, options.stateManager, {
|
|
139
136
|
bufferSize: options.bufferSize ?? 1000,
|
|
140
137
|
bufferThreshold: Math.ceil((options.bufferSize ?? 1000) * 0.1),
|
|
141
138
|
maxRedeliveryCount: options.maxRedeliveryCount ?? 3,
|
|
142
|
-
achknowledgeTimeoutMs: options.achknowledgeTimeoutMs ??
|
|
139
|
+
achknowledgeTimeoutMs: options.achknowledgeTimeoutMs ?? 5_000,
|
|
143
140
|
includeSensitiveData: options.includeSensitiveData ?? false,
|
|
144
141
|
processor: options.processor,
|
|
145
142
|
stopAt: options.stopAt,
|
|
@@ -276,14 +273,12 @@ class FlowcoreDataPump {
|
|
|
276
273
|
}
|
|
277
274
|
const events = [];
|
|
278
275
|
const deliveryId = crypto.randomUUID();
|
|
279
|
-
const reservedBufferItems = [];
|
|
280
276
|
for (const event of this.buffer) {
|
|
281
277
|
if (event.status === "open") {
|
|
282
278
|
event.status = "reserved";
|
|
283
279
|
event.deliveryId = deliveryId;
|
|
284
280
|
event.deliveryCount++;
|
|
285
281
|
events.push(event.event);
|
|
286
|
-
reservedBufferItems.push(event);
|
|
287
282
|
this.incMetricsCounter("pulled", event.event.eventType, JSON.stringify(event.event).length);
|
|
288
283
|
if (events.length === amount) {
|
|
289
284
|
break;
|
|
@@ -295,13 +290,9 @@ class FlowcoreDataPump {
|
|
|
295
290
|
return this.reserve(amount);
|
|
296
291
|
}
|
|
297
292
|
this.updateMetricsGauges();
|
|
298
|
-
|
|
293
|
+
setTimeout(() => {
|
|
299
294
|
this.reOpen(events.map((event) => event.eventId), deliveryId);
|
|
300
295
|
}, this.options.achknowledgeTimeoutMs);
|
|
301
|
-
// Store timeout ID in all reserved items so we can clear it on acknowledgment
|
|
302
|
-
for (const item of reservedBufferItems) {
|
|
303
|
-
item.timeoutId = timeoutId;
|
|
304
|
-
}
|
|
305
296
|
return events;
|
|
306
297
|
}
|
|
307
298
|
async acknowledge(eventIds) {
|
|
@@ -309,22 +300,13 @@ class FlowcoreDataPump {
|
|
|
309
300
|
return;
|
|
310
301
|
}
|
|
311
302
|
const lastEventInBuffer = this.buffer[this.buffer.length - 1];
|
|
312
|
-
const acknowledgedTimeoutIds = new Set();
|
|
313
303
|
this.buffer = this.buffer.filter((event) => {
|
|
314
304
|
if (eventIds.includes(event.event.eventId)) {
|
|
315
305
|
this.incMetricsCounter("acknowledged", event.event.eventType, 1);
|
|
316
|
-
// Collect timeout IDs to clear them
|
|
317
|
-
if (event.timeoutId !== undefined) {
|
|
318
|
-
acknowledgedTimeoutIds.add(event.timeoutId);
|
|
319
|
-
}
|
|
320
306
|
return false;
|
|
321
307
|
}
|
|
322
308
|
return true;
|
|
323
309
|
});
|
|
324
|
-
// Clear timeouts for acknowledged events to prevent unnecessary reOpen calls
|
|
325
|
-
for (const timeoutId of acknowledgedTimeoutIds) {
|
|
326
|
-
clearTimeout(timeoutId);
|
|
327
|
-
}
|
|
328
310
|
if (this.buffer.length <= this.options.bufferSize - this.options.bufferThreshold) {
|
|
329
311
|
this.waiterBufferThreshold?.();
|
|
330
312
|
}
|
|
@@ -340,23 +322,14 @@ class FlowcoreDataPump {
|
|
|
340
322
|
}
|
|
341
323
|
const lastEventInBuffer = this.buffer[this.buffer.length - 1];
|
|
342
324
|
const failedEvents = [];
|
|
343
|
-
const failedTimeoutIds = new Set();
|
|
344
325
|
this.buffer = this.buffer.filter((event) => {
|
|
345
326
|
if (eventIds.includes(event.event.eventId)) {
|
|
346
327
|
this.incMetricsCounter("failed", event.event.eventType, 1);
|
|
347
328
|
failedEvents.push(event.event);
|
|
348
|
-
// Collect timeout IDs to clear them
|
|
349
|
-
if (event.timeoutId !== undefined) {
|
|
350
|
-
failedTimeoutIds.add(event.timeoutId);
|
|
351
|
-
}
|
|
352
329
|
return false;
|
|
353
330
|
}
|
|
354
331
|
return true;
|
|
355
332
|
});
|
|
356
|
-
// Clear timeouts for failed events
|
|
357
|
-
for (const timeoutId of failedTimeoutIds) {
|
|
358
|
-
clearTimeout(timeoutId);
|
|
359
|
-
}
|
|
360
333
|
this.logger?.info(`Failed ${failedEvents.length} events`);
|
|
361
334
|
void this.options.processor?.failedHandler?.(failedEvents);
|
|
362
335
|
if (this.buffer.length <= this.options.bufferSize - this.options.bufferThreshold) {
|
|
@@ -383,7 +356,6 @@ class FlowcoreDataPump {
|
|
|
383
356
|
}
|
|
384
357
|
event.status = "open";
|
|
385
358
|
event.deliveryId = undefined;
|
|
386
|
-
event.timeoutId = undefined;
|
|
387
359
|
reopenedEvents.push(event.event);
|
|
388
360
|
return true;
|
|
389
361
|
});
|