dynamic-throttled-queue 2.3.0-rc.120625e → 2.3.0-rc.477ab9c
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/README.md +1 -1
- package/dist/adaptive-rate.d.ts +48 -20
- package/dist/adaptive-rate.js +97 -30
- package/dist/adaptive-rate.js.map +1 -1
- package/dist/dynamic-throttled-queue.d.ts +7 -67
- package/dist/dynamic-throttled-queue.js +17 -50
- package/dist/dynamic-throttled-queue.js.map +1 -1
- package/dist/retry-policy.d.ts +25 -0
- package/dist/retry-policy.js +73 -0
- package/dist/retry-policy.js.map +1 -0
- package/dist/scheduler.d.ts +35 -2
- package/dist/scheduler.js +21 -64
- package/dist/scheduler.js.map +1 -1
- package/package.json +8 -10
- package/dist/retry-backoff.d.ts +0 -2
- package/dist/retry-backoff.js +0 -31
- package/dist/retry-backoff.js.map +0 -1
package/README.md
CHANGED
|
@@ -62,7 +62,7 @@ Set `maxQueueSize` to bound accepted work. Capacity is reserved from enqueue thr
|
|
|
62
62
|
| `retryClassifier` | `RetryClassifier` | — | Decides whether a failed callback outcome is eligible for another attempt |
|
|
63
63
|
| `onRateChange` | `(rate: number) => void` | — | Called when the current rate changes |
|
|
64
64
|
|
|
65
|
-
`retry`, `errors_per_interval`, `compact_threshold`, and `maxQueueSize` reject fractional and non-finite values. `errors_per_interval` must be at least `1`; `retry` and `compact_threshold` may be `0`. `retryBackoff.baseDelay` and optional `maxDelay` are finite non-negative millisecond values (fractional values are accepted); optional `jitter` is finite from `0` through `1`.
|
|
65
|
+
`retry`, `errors_per_interval`, `compact_threshold`, and `maxQueueSize` reject fractional and non-finite values. `errors_per_interval` must be at least `1`; `retry` and `compact_threshold` may be `0`. `retryBackoff.strategy` must be `fixed`, `linear`, or `exponential`. `retryBackoff.baseDelay` and optional `maxDelay` are finite non-negative millisecond values (fractional values are accepted); optional `jitter` is finite from `0` through `1`.
|
|
66
66
|
|
|
67
67
|
`retryBackoff` is `{ strategy: "fixed" | "linear" | "exponential"; baseDelay: number; maxDelay?: number; jitter?: number; random?: () => number }`. The first retry has index `1`: fixed uses `baseDelay`, linear uses `baseDelay × retryIndex`, and exponential uses `baseDelay × 2^(retryIndex - 1)`. The calculated delay is capped at `maxDelay`, when supplied, then optional symmetric percentage jitter is applied and capped again. `random` makes jitter deterministic for tests; a thrown, non-finite, or out-of-range result safely falls back to no jitter. Retry backoff begins when the failed attempt settles and is independent of adaptive-rate `back_off`.
|
|
68
68
|
|
package/dist/adaptive-rate.d.ts
CHANGED
|
@@ -1,17 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export type RateStrategyObservation = Readonly<{
|
|
2
|
+
currentRate: number;
|
|
3
|
+
minRate: number;
|
|
4
|
+
maxRate: number;
|
|
5
|
+
errorCount: number;
|
|
6
|
+
errorThreshold: number;
|
|
7
|
+
hasPendingWork: boolean;
|
|
8
|
+
wasBackedOff: boolean;
|
|
9
|
+
}>;
|
|
10
|
+
export type RateStrategyDecision = Readonly<{
|
|
11
|
+
nextRate: number;
|
|
12
|
+
shouldBackOff: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
export type RateStrategy = (observation: RateStrategyObservation) => RateStrategyDecision;
|
|
15
|
+
export type AimdOptions = {
|
|
16
|
+
increaseBy?: number;
|
|
17
|
+
decreaseFactor?: number;
|
|
18
|
+
};
|
|
19
|
+
export type RateFailureOutcome = Readonly<{
|
|
20
|
+
kind: "returned-false";
|
|
21
|
+
}> | Readonly<{
|
|
22
|
+
kind: "thrown";
|
|
23
|
+
error: unknown;
|
|
24
|
+
}> | Readonly<{
|
|
25
|
+
kind: "rejected";
|
|
26
|
+
error: unknown;
|
|
27
|
+
}>;
|
|
28
|
+
export type RateOutcomeClassifier = (outcome: RateFailureOutcome) => boolean;
|
|
29
|
+
export type AdjustmentTiming = "interval" | "settled";
|
|
30
|
+
export declare const linear: RateStrategy;
|
|
31
|
+
export declare function aimd({ increaseBy, decreaseFactor }?: AimdOptions): RateStrategy;
|
|
7
32
|
/** Reports how one started callback settled: `undefined` for success, otherwise the failure. */
|
|
8
33
|
export type SettlementReporter = (outcome: RateFailureOutcome | undefined) => void;
|
|
9
34
|
export type AdaptiveRateOptions = {
|
|
10
|
-
|
|
11
|
-
|
|
35
|
+
minRate: number;
|
|
36
|
+
maxRate: number;
|
|
12
37
|
interval: number;
|
|
13
|
-
|
|
14
|
-
|
|
38
|
+
/** Makes one start due every `interval / rate` ms instead of `rate` starts once per interval. */
|
|
39
|
+
evenlySpaced: boolean;
|
|
40
|
+
errorThreshold: number;
|
|
41
|
+
backOff: boolean;
|
|
15
42
|
adjustmentTiming: AdjustmentTiming;
|
|
16
43
|
rateStrategy: RateStrategy;
|
|
17
44
|
rateOutcomeClassifier?: RateOutcomeClassifier;
|
|
@@ -20,12 +47,12 @@ export type AdaptiveRateOptions = {
|
|
|
20
47
|
export type AdaptiveRateHost = {
|
|
21
48
|
/** Whether accepted work is waiting to start. */
|
|
22
49
|
hasPendingWork: () => boolean;
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
50
|
+
/**
|
|
51
|
+
* Starts are due: start up to `limit` queued callbacks as concurrency allows, calling `started()` for each.
|
|
52
|
+
* Returns whether a slot is still free. When none is, no further start becomes due until `start()`
|
|
53
|
+
* reports a freed slot.
|
|
54
|
+
*/
|
|
55
|
+
startsDue: (limit: number) => boolean;
|
|
29
56
|
/** The rate strategy failed; the host must call `stop()`. The error is rethrown after this returns. */
|
|
30
57
|
failed: (error: unknown) => void;
|
|
31
58
|
};
|
|
@@ -33,11 +60,12 @@ export type AdaptiveRate = {
|
|
|
33
60
|
readonly rate: number;
|
|
34
61
|
readonly rateIncreases: number;
|
|
35
62
|
readonly rateDecreases: number;
|
|
36
|
-
|
|
37
|
-
|
|
63
|
+
/**
|
|
64
|
+
* Ends a pause, then begins observing if idle and work is pending. While starts are open and no start
|
|
65
|
+
* is scheduled (concurrency was full), makes starts due now once a spacing has passed since the last
|
|
66
|
+
* start, or schedules them for when it has. During `startsDue`, the batch's own follow-up covers it.
|
|
67
|
+
*/
|
|
38
68
|
start: () => void;
|
|
39
|
-
/** Reports that every queued callback has started. */
|
|
40
|
-
drained: () => void;
|
|
41
69
|
/** Ends observation. Settled timing discards its in-progress window. */
|
|
42
70
|
stop: () => void;
|
|
43
71
|
/** Stops and discards the observation. Settlements are ignored until `start()` or `stop()`. */
|
package/dist/adaptive-rate.js
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
export const linear = ({ minRate, maxRate, currentRate, errorCount, errorThreshold, hasPendingWork, wasBackedOff, }) => {
|
|
2
|
+
if (errorCount >= errorThreshold) {
|
|
3
|
+
return { nextRate: Math.max(minRate, currentRate - 1), shouldBackOff: true };
|
|
4
|
+
}
|
|
5
|
+
if (!wasBackedOff && errorCount === 0 && hasPendingWork) {
|
|
6
|
+
return { nextRate: Math.min(maxRate, currentRate + 1), shouldBackOff: false };
|
|
7
|
+
}
|
|
8
|
+
return { nextRate: currentRate, shouldBackOff: false };
|
|
9
|
+
};
|
|
10
|
+
export function aimd({ increaseBy = 1, decreaseFactor = 0.5 } = {}) {
|
|
11
|
+
if (!Number.isInteger(increaseBy) || increaseBy < 1) {
|
|
12
|
+
throw new Error("increaseBy must be a positive integer");
|
|
13
|
+
}
|
|
14
|
+
if (!Number.isFinite(decreaseFactor) || decreaseFactor <= 0 || decreaseFactor >= 1) {
|
|
15
|
+
throw new Error("decreaseFactor must be a number greater than 0 and less than 1");
|
|
16
|
+
}
|
|
17
|
+
return ({ currentRate, errorCount, errorThreshold, hasPendingWork, wasBackedOff }) => {
|
|
18
|
+
if (errorCount >= errorThreshold) {
|
|
19
|
+
return { nextRate: Math.floor(currentRate * decreaseFactor), shouldBackOff: true };
|
|
20
|
+
}
|
|
21
|
+
if (!wasBackedOff && errorCount === 0 && hasPendingWork) {
|
|
22
|
+
return { nextRate: currentRate + increaseBy, shouldBackOff: false };
|
|
23
|
+
}
|
|
24
|
+
return { nextRate: currentRate, shouldBackOff: false };
|
|
25
|
+
};
|
|
26
|
+
}
|
|
1
27
|
const ignoreSettlement = () => { };
|
|
2
28
|
function validateDecision(decision) {
|
|
3
29
|
if (typeof decision !== "object" || decision === null) {
|
|
@@ -49,6 +75,7 @@ function settledTiming(context) {
|
|
|
49
75
|
let timer;
|
|
50
76
|
let window = 0;
|
|
51
77
|
let collecting = false;
|
|
78
|
+
let starts = 0;
|
|
52
79
|
let outstanding = 0;
|
|
53
80
|
function open() {
|
|
54
81
|
timer = undefined;
|
|
@@ -58,12 +85,18 @@ function settledTiming(context) {
|
|
|
58
85
|
}
|
|
59
86
|
window++;
|
|
60
87
|
collecting = true;
|
|
88
|
+
starts = 0;
|
|
61
89
|
outstanding = 0;
|
|
62
90
|
context.resume();
|
|
63
91
|
timer = setTimeout(close, context.interval);
|
|
64
92
|
}
|
|
65
93
|
function close() {
|
|
66
94
|
timer = undefined;
|
|
95
|
+
// An empty collection interval makes no decision; collect again, or go idle when nothing is pending.
|
|
96
|
+
if (starts === 0) {
|
|
97
|
+
open();
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
67
100
|
collecting = false;
|
|
68
101
|
context.hold();
|
|
69
102
|
if (outstanding === 0)
|
|
@@ -75,22 +108,17 @@ function settledTiming(context) {
|
|
|
75
108
|
if (current !== window)
|
|
76
109
|
return;
|
|
77
110
|
if (hold)
|
|
78
|
-
timer = setTimeout(
|
|
111
|
+
timer = setTimeout(open, context.interval);
|
|
79
112
|
else
|
|
80
113
|
open();
|
|
81
114
|
}
|
|
82
|
-
function endBackoff() {
|
|
83
|
-
timer = undefined;
|
|
84
|
-
context.endBackoff();
|
|
85
|
-
if (context.hasPendingWork())
|
|
86
|
-
open();
|
|
87
|
-
}
|
|
88
115
|
return {
|
|
89
116
|
start: open,
|
|
90
117
|
started() {
|
|
91
118
|
if (!collecting)
|
|
92
119
|
return ignoreSettlement;
|
|
93
120
|
const startedIn = window;
|
|
121
|
+
starts++;
|
|
94
122
|
outstanding++;
|
|
95
123
|
return outcome => {
|
|
96
124
|
if (startedIn !== window)
|
|
@@ -112,14 +140,18 @@ function settledTiming(context) {
|
|
|
112
140
|
};
|
|
113
141
|
}
|
|
114
142
|
export function createAdaptiveRate(options, host) {
|
|
115
|
-
const {
|
|
116
|
-
let rate = Math.ceil((
|
|
143
|
+
const { minRate, maxRate, interval, evenlySpaced, errorThreshold, backOff, rateStrategy, rateOutcomeClassifier, onRateChange, } = options;
|
|
144
|
+
let rate = Math.ceil((maxRate + minRate) / 2);
|
|
117
145
|
let rateIncreases = 0;
|
|
118
146
|
let rateDecreases = 0;
|
|
119
147
|
let errorCount = 0;
|
|
120
148
|
let wasBackedOff = false;
|
|
121
149
|
let ignoringSettlements = false;
|
|
122
150
|
let pacing = "idle";
|
|
151
|
+
let lastStart = 0;
|
|
152
|
+
let startTimer;
|
|
153
|
+
let dispatching = false;
|
|
154
|
+
let batchStarts = 0;
|
|
123
155
|
function isRateReducing(outcome) {
|
|
124
156
|
try {
|
|
125
157
|
return rateOutcomeClassifier?.(outcome) ?? true;
|
|
@@ -141,10 +173,10 @@ export function createAdaptiveRate(options, host) {
|
|
|
141
173
|
function decide() {
|
|
142
174
|
const observation = Object.freeze({
|
|
143
175
|
currentRate: rate,
|
|
144
|
-
minRate
|
|
145
|
-
maxRate
|
|
176
|
+
minRate,
|
|
177
|
+
maxRate,
|
|
146
178
|
errorCount,
|
|
147
|
-
errorThreshold
|
|
179
|
+
errorThreshold,
|
|
148
180
|
hasPendingWork: host.hasPendingWork(),
|
|
149
181
|
wasBackedOff,
|
|
150
182
|
});
|
|
@@ -156,14 +188,47 @@ export function createAdaptiveRate(options, host) {
|
|
|
156
188
|
host.failed(error);
|
|
157
189
|
throw error;
|
|
158
190
|
}
|
|
159
|
-
const hold =
|
|
191
|
+
const hold = backOff && decision.shouldBackOff;
|
|
160
192
|
errorCount = 0;
|
|
161
193
|
wasBackedOff = hold;
|
|
162
|
-
applyRate(Math.min(
|
|
194
|
+
applyRate(Math.min(maxRate, Math.max(minRate, decision.nextRate)));
|
|
163
195
|
return hold;
|
|
164
196
|
}
|
|
197
|
+
function spacing() {
|
|
198
|
+
return evenlySpaced ? interval / rate : interval;
|
|
199
|
+
}
|
|
200
|
+
function scheduleStart(delay) {
|
|
201
|
+
clearTimeout(startTimer);
|
|
202
|
+
startTimer = setTimeout(startDue, delay);
|
|
203
|
+
}
|
|
204
|
+
function cancelStart() {
|
|
205
|
+
clearTimeout(startTimer);
|
|
206
|
+
startTimer = undefined;
|
|
207
|
+
}
|
|
208
|
+
/** Makes a batch of starts due once one spacing has passed since the last start. */
|
|
209
|
+
function startDue() {
|
|
210
|
+
startTimer = undefined;
|
|
211
|
+
const wait = lastStart + spacing() - Date.now();
|
|
212
|
+
if (wait > 0) {
|
|
213
|
+
scheduleStart(wait);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
dispatching = true;
|
|
217
|
+
batchStarts = 0;
|
|
218
|
+
let slotFree;
|
|
219
|
+
try {
|
|
220
|
+
slotFree = host.startsDue(evenlySpaced ? 1 : rate);
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
dispatching = false;
|
|
224
|
+
}
|
|
225
|
+
if (!host.hasPendingWork())
|
|
226
|
+
timing.drained();
|
|
227
|
+
if (pacing === "open" && slotFree)
|
|
228
|
+
scheduleStart(spacing());
|
|
229
|
+
}
|
|
165
230
|
const context = {
|
|
166
|
-
interval
|
|
231
|
+
interval,
|
|
167
232
|
get pacing() {
|
|
168
233
|
return pacing;
|
|
169
234
|
},
|
|
@@ -175,22 +240,23 @@ export function createAdaptiveRate(options, host) {
|
|
|
175
240
|
decide,
|
|
176
241
|
resume() {
|
|
177
242
|
pacing = "open";
|
|
178
|
-
|
|
243
|
+
lastStart = Date.now();
|
|
244
|
+
scheduleStart(spacing());
|
|
179
245
|
},
|
|
180
246
|
hold(deferBy) {
|
|
181
247
|
pacing = "held";
|
|
182
|
-
|
|
248
|
+
if (deferBy === undefined)
|
|
249
|
+
cancelStart();
|
|
250
|
+
else
|
|
251
|
+
scheduleStart(spacing() + deferBy);
|
|
183
252
|
},
|
|
184
253
|
reopen() {
|
|
185
254
|
pacing = "open";
|
|
186
255
|
},
|
|
187
|
-
endBackoff() {
|
|
188
|
-
wasBackedOff = false;
|
|
189
|
-
},
|
|
190
256
|
idle() {
|
|
191
257
|
wasBackedOff = false;
|
|
192
258
|
pacing = "idle";
|
|
193
|
-
|
|
259
|
+
cancelStart();
|
|
194
260
|
},
|
|
195
261
|
};
|
|
196
262
|
const timing = options.adjustmentTiming === "settled" ? settledTiming(context) : intervalTiming(context);
|
|
@@ -204,17 +270,14 @@ export function createAdaptiveRate(options, host) {
|
|
|
204
270
|
get rateDecreases() {
|
|
205
271
|
return rateDecreases;
|
|
206
272
|
},
|
|
207
|
-
get pacing() {
|
|
208
|
-
return pacing;
|
|
209
|
-
},
|
|
210
273
|
start() {
|
|
211
274
|
ignoringSettlements = false;
|
|
212
|
-
if (
|
|
275
|
+
if (!host.hasPendingWork())
|
|
213
276
|
return;
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
277
|
+
if (pacing === "idle")
|
|
278
|
+
timing.start();
|
|
279
|
+
else if (pacing === "open" && startTimer === undefined && !dispatching)
|
|
280
|
+
startDue();
|
|
218
281
|
},
|
|
219
282
|
stop() {
|
|
220
283
|
ignoringSettlements = false;
|
|
@@ -225,7 +288,11 @@ export function createAdaptiveRate(options, host) {
|
|
|
225
288
|
errorCount = 0;
|
|
226
289
|
ignoringSettlements = true;
|
|
227
290
|
},
|
|
228
|
-
started
|
|
291
|
+
started() {
|
|
292
|
+
if (dispatching && batchStarts++ === 0)
|
|
293
|
+
lastStart = Date.now();
|
|
294
|
+
return timing.started();
|
|
295
|
+
},
|
|
229
296
|
};
|
|
230
297
|
}
|
|
231
298
|
//# sourceMappingURL=adaptive-rate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adaptive-rate.js","sourceRoot":"","sources":["../src/adaptive-rate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adaptive-rate.js","sourceRoot":"","sources":["../src/adaptive-rate.ts"],"names":[],"mappings":"AA+BA,MAAM,CAAC,MAAM,MAAM,GAAiB,CAAC,EACnC,OAAO,EACP,OAAO,EACP,WAAW,EACX,UAAU,EACV,cAAc,EACd,cAAc,EACd,YAAY,GACb,EAAE,EAAE;IACH,IAAI,UAAU,IAAI,cAAc,EAAE,CAAC;QACjC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,GAAG,CAAC,CAAC,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;IAC/E,CAAC;IACD,IAAI,CAAC,YAAY,IAAI,UAAU,KAAK,CAAC,IAAI,cAAc,EAAE,CAAC;QACxD,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,WAAW,GAAG,CAAC,CAAC,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IAChF,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;AACzD,CAAC,CAAC;AAEF,MAAM,UAAU,IAAI,CAAC,EAAE,UAAU,GAAG,CAAC,EAAE,cAAc,GAAG,GAAG,KAAkB,EAAE;IAC7E,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;QACpD,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;IAC3D,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,cAAc,IAAI,CAAC,IAAI,cAAc,IAAI,CAAC,EAAE,CAAC;QACnF,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CA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|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
export type RateStrategyObservation = Readonly<{
|
|
9
|
-
currentRate: number;
|
|
10
|
-
minRate: number;
|
|
11
|
-
maxRate: number;
|
|
12
|
-
errorCount: number;
|
|
13
|
-
errorThreshold: number;
|
|
14
|
-
hasPendingWork: boolean;
|
|
15
|
-
wasBackedOff: boolean;
|
|
16
|
-
}>;
|
|
17
|
-
export type RateStrategyDecision = Readonly<{
|
|
18
|
-
nextRate: number;
|
|
19
|
-
shouldBackOff: boolean;
|
|
20
|
-
}>;
|
|
21
|
-
export type RateStrategy = (observation: RateStrategyObservation) => RateStrategyDecision;
|
|
22
|
-
export type AimdOptions = {
|
|
23
|
-
increaseBy?: number;
|
|
24
|
-
decreaseFactor?: number;
|
|
25
|
-
};
|
|
26
|
-
export type RateFailureOutcome = Readonly<{
|
|
27
|
-
kind: "returned-false";
|
|
28
|
-
}> | Readonly<{
|
|
29
|
-
kind: "thrown";
|
|
30
|
-
error: unknown;
|
|
31
|
-
}> | Readonly<{
|
|
32
|
-
kind: "rejected";
|
|
33
|
-
error: unknown;
|
|
34
|
-
}>;
|
|
35
|
-
export type RateOutcomeClassifier = (outcome: RateFailureOutcome) => boolean;
|
|
36
|
-
export type RetryClassifier = (outcome: RateFailureOutcome, attempt: number) => boolean;
|
|
37
|
-
export type AdjustmentTiming = "interval" | "settled";
|
|
38
|
-
export declare const linear: RateStrategy;
|
|
39
|
-
export declare function aimd({ increaseBy, decreaseFactor }?: AimdOptions): RateStrategy;
|
|
40
|
-
export type ExecutionContext = Readonly<{
|
|
41
|
-
signal: AbortSignal;
|
|
42
|
-
}>;
|
|
43
|
-
/** Return `false` to signal failure (increments error count, triggers retry if configured). */
|
|
44
|
-
export type ThrottleCallback = (context: ExecutionContext) => boolean | void | Promise<boolean | void>;
|
|
1
|
+
import type { AdjustmentTiming, RateOutcomeClassifier, RateStrategy } from "./adaptive-rate.js";
|
|
2
|
+
import type { RetryBackoff, RetryClassifier } from "./retry-policy.js";
|
|
3
|
+
import type { ThrottleHandle } from "./scheduler.js";
|
|
4
|
+
export { aimd, linear } from "./adaptive-rate.js";
|
|
5
|
+
export type { AdjustmentTiming, AimdOptions, RateFailureOutcome, RateOutcomeClassifier, RateStrategy, RateStrategyDecision, RateStrategyObservation } from "./adaptive-rate.js";
|
|
6
|
+
export type { RetryBackoff, RetryClassifier } from "./retry-policy.js";
|
|
7
|
+
export type { ExecutionContext, QueueLifecycleState, QueueState, ThrottleCallback, ThrottleFn, ThrottleHandle } from "./scheduler.js";
|
|
45
8
|
export type ThrottleOptions = {
|
|
46
9
|
min_rpi: number;
|
|
47
10
|
interval: number;
|
|
@@ -70,27 +33,4 @@ export type ThrottleOptions = {
|
|
|
70
33
|
adjustmentTiming?: AdjustmentTiming;
|
|
71
34
|
onRateChange?: (rate: number) => void;
|
|
72
35
|
};
|
|
73
|
-
export type ThrottleFn = (callback: ThrottleCallback) => void;
|
|
74
|
-
export type QueueLifecycleState = "running" | "paused" | "stopped" | "aborted" | "failed";
|
|
75
|
-
export type QueueState = Readonly<{
|
|
76
|
-
rate: number;
|
|
77
|
-
pending: number;
|
|
78
|
-
active: number;
|
|
79
|
-
state: QueueLifecycleState;
|
|
80
|
-
started: number;
|
|
81
|
-
succeeded: number;
|
|
82
|
-
failed: number;
|
|
83
|
-
retried: number;
|
|
84
|
-
rateIncreases: number;
|
|
85
|
-
rateDecreases: number;
|
|
86
|
-
}>;
|
|
87
|
-
export type ThrottleHandle = ThrottleFn & {
|
|
88
|
-
pause: () => void;
|
|
89
|
-
resume: () => void;
|
|
90
|
-
stop: () => void;
|
|
91
|
-
abort: () => void;
|
|
92
|
-
waitForIdle: () => Promise<void>;
|
|
93
|
-
getState: () => QueueState;
|
|
94
|
-
readonly pending: number;
|
|
95
|
-
};
|
|
96
36
|
export declare function createThrottledQueue(options: ThrottleOptions): ThrottleHandle;
|
|
@@ -1,46 +1,11 @@
|
|
|
1
|
+
import { linear } from "./adaptive-rate.js";
|
|
2
|
+
import { createRetryPolicy } from "./retry-policy.js";
|
|
1
3
|
import { createScheduler } from "./scheduler.js";
|
|
4
|
+
// eslint-disable-next-line no-barrel-files/no-barrel-files -- The package entry exposes the rate strategies owned by the adaptive-rate module.
|
|
5
|
+
export { aimd, linear } from "./adaptive-rate.js";
|
|
2
6
|
const adjustmentTimings = new Set(["interval", "settled"]);
|
|
3
|
-
export const linear = ({ minRate, maxRate, currentRate, errorCount, errorThreshold, hasPendingWork, wasBackedOff, }) => {
|
|
4
|
-
if (errorCount >= errorThreshold) {
|
|
5
|
-
return { nextRate: Math.max(minRate, currentRate - 1), shouldBackOff: true };
|
|
6
|
-
}
|
|
7
|
-
if (!wasBackedOff && errorCount === 0 && hasPendingWork) {
|
|
8
|
-
return { nextRate: Math.min(maxRate, currentRate + 1), shouldBackOff: false };
|
|
9
|
-
}
|
|
10
|
-
return { nextRate: currentRate, shouldBackOff: false };
|
|
11
|
-
};
|
|
12
|
-
export function aimd({ increaseBy = 1, decreaseFactor = 0.5 } = {}) {
|
|
13
|
-
if (!Number.isInteger(increaseBy) || increaseBy < 1) {
|
|
14
|
-
throw new Error("increaseBy must be a positive integer");
|
|
15
|
-
}
|
|
16
|
-
if (!Number.isFinite(decreaseFactor) || decreaseFactor <= 0 || decreaseFactor >= 1) {
|
|
17
|
-
throw new Error("decreaseFactor must be a number greater than 0 and less than 1");
|
|
18
|
-
}
|
|
19
|
-
return ({ currentRate, errorCount, errorThreshold, hasPendingWork, wasBackedOff }) => {
|
|
20
|
-
if (errorCount >= errorThreshold) {
|
|
21
|
-
return { nextRate: Math.floor(currentRate * decreaseFactor), shouldBackOff: true };
|
|
22
|
-
}
|
|
23
|
-
if (!wasBackedOff && errorCount === 0 && hasPendingWork) {
|
|
24
|
-
return { nextRate: currentRate + increaseBy, shouldBackOff: false };
|
|
25
|
-
}
|
|
26
|
-
return { nextRate: currentRate, shouldBackOff: false };
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
function validateRetryBackoff(retryBackoff) {
|
|
30
|
-
if (retryBackoff === undefined)
|
|
31
|
-
return;
|
|
32
|
-
if (!Number.isFinite(retryBackoff.baseDelay) || retryBackoff.baseDelay < 0) {
|
|
33
|
-
throw new Error("retryBackoff.baseDelay must be a finite non-negative number");
|
|
34
|
-
}
|
|
35
|
-
if (retryBackoff.maxDelay !== undefined && (!Number.isFinite(retryBackoff.maxDelay) || retryBackoff.maxDelay < 0)) {
|
|
36
|
-
throw new Error("retryBackoff.maxDelay must be a finite non-negative number");
|
|
37
|
-
}
|
|
38
|
-
if (retryBackoff.jitter !== undefined && (!Number.isFinite(retryBackoff.jitter) || retryBackoff.jitter < 0 || retryBackoff.jitter > 1)) {
|
|
39
|
-
throw new Error("retryBackoff.jitter must be a finite number from 0 through 1");
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
7
|
export function createThrottledQueue(options) {
|
|
43
|
-
const { min_rpi, interval, max_rpi = min_rpi, concurrency, maxQueueSize,
|
|
8
|
+
const { min_rpi, interval, max_rpi = min_rpi, concurrency, maxQueueSize, compact_threshold = 512 } = options;
|
|
44
9
|
const errors_per_interval = options.errors_per_interval ?? 5;
|
|
45
10
|
if (!Number.isInteger(min_rpi) || min_rpi < 1) {
|
|
46
11
|
throw new Error("min_rpi must be a positive integer");
|
|
@@ -60,26 +25,28 @@ export function createThrottledQueue(options) {
|
|
|
60
25
|
if (!Number.isInteger(errors_per_interval) || errors_per_interval < 1) {
|
|
61
26
|
throw new Error("errors_per_interval must be a positive integer");
|
|
62
27
|
}
|
|
63
|
-
if (!Number.isInteger(retry) || retry < 0) {
|
|
64
|
-
throw new Error("retry must be a non-negative integer");
|
|
65
|
-
}
|
|
66
28
|
if (!Number.isInteger(compact_threshold) || compact_threshold < 0) {
|
|
67
29
|
throw new Error("compact_threshold must be a non-negative integer");
|
|
68
30
|
}
|
|
69
31
|
if (options.adjustmentTiming !== undefined && !adjustmentTimings.has(options.adjustmentTiming)) {
|
|
70
32
|
throw new Error("adjustmentTiming must be either interval or settled");
|
|
71
33
|
}
|
|
72
|
-
|
|
73
|
-
return createScheduler(
|
|
74
|
-
|
|
75
|
-
|
|
34
|
+
const retryPolicy = createRetryPolicy(options);
|
|
35
|
+
return createScheduler({
|
|
36
|
+
concurrency: concurrency ?? Infinity,
|
|
37
|
+
capacity: maxQueueSize ?? Infinity,
|
|
38
|
+
compactThreshold: compact_threshold,
|
|
39
|
+
}, {
|
|
40
|
+
minRate: min_rpi,
|
|
41
|
+
maxRate: max_rpi,
|
|
76
42
|
interval,
|
|
77
|
-
|
|
78
|
-
|
|
43
|
+
evenlySpaced: options.evenly_spaced ?? true,
|
|
44
|
+
errorThreshold: errors_per_interval,
|
|
45
|
+
backOff: options.back_off ?? false,
|
|
79
46
|
adjustmentTiming: options.adjustmentTiming ?? "interval",
|
|
80
47
|
rateStrategy: options.rateStrategy ?? linear,
|
|
81
48
|
rateOutcomeClassifier: options.rateOutcomeClassifier,
|
|
82
49
|
onRateChange: options.onRateChange,
|
|
83
|
-
});
|
|
50
|
+
}, retryPolicy);
|
|
84
51
|
}
|
|
85
52
|
//# sourceMappingURL=dynamic-throttled-queue.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dynamic-throttled-queue.js","sourceRoot":"","sources":["../src/dynamic-throttled-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"dynamic-throttled-queue.js","sourceRoot":"","sources":["../src/dynamic-throttled-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,2BAA2B;AAE5C,OAAO,EAAE,iBAAiB,EAAE,0BAA0B;AAEtD,OAAO,EAAE,eAAe,EAAE,uBAAuB;AAGjD,+IAA+I;AAC/I,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,2BAA2B;AAQlD,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAAS,CAAE,UAAU,EAAE,SAAS,CAAE,CAAC,CAAC;AA+BrE,MAAM,UAAU,oBAAoB,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AAC,iBAAiB,CAAC,IAAI,iBAAiB,GAAG,CAAC,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,IAAI,OAAO,CAAC,gBAAgB,KAAK,SAAS,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;QAC/F,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAC;IACzE,CAAC;IACD,MAAM,WAAW,GAAG,iBAAiB,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,eAAe,CAAC;QACrB,WAAW,EAAE,WAAW,IAAI,QAAQ;QACpC,QAAQ,EAAE,YAAY,IAAI,QAAQ;QAClC,gBAAgB,EAAE,iBAAiB;KACpC,EAAE;QACD,OAAO,EAAE,OAAO;QAChB,OAAO,EAAE,OAAO;QAChB,QAAQ;QACR,YAAY,EAAE,OAAO,CAAC,aAAa,IAAI,IAAI;QAC3C,cAAc,EAAE,mBAAmB;QACnC,OAAO,EAAE,OAAO,CAAC,QAAQ,IAAI,KAAK;QAClC,gBAAgB,EAAE,OAAO,CAAC,gBAAgB,IAAI,UAAU;QACxD,YAAY,EAAE,OAAO,CAAC,YAAY,IAAI,MAAM;QAC5C,qBAAqB,EAAE,OAAO,CAAC,qBAAqB;QACpD,YAAY,EAAE,OAAO,CAAC,YAAY;KACnC,EAAE,WAAW,CAAC,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { RateFailureOutcome } from "./adaptive-rate.js";
|
|
2
|
+
export type RetryBackoff = {
|
|
3
|
+
strategy: "fixed" | "linear" | "exponential";
|
|
4
|
+
baseDelay: number;
|
|
5
|
+
maxDelay?: number;
|
|
6
|
+
jitter?: number;
|
|
7
|
+
random?: () => number;
|
|
8
|
+
};
|
|
9
|
+
export type RetryClassifier = (outcome: RateFailureOutcome, attempt: number) => boolean;
|
|
10
|
+
export type RetryPolicyOptions = {
|
|
11
|
+
retry?: number;
|
|
12
|
+
retryBackoff?: RetryBackoff;
|
|
13
|
+
retryClassifier?: RetryClassifier;
|
|
14
|
+
};
|
|
15
|
+
/** How a failed attempt continues: `{}` retries now, `{ delay }` retries after `delay` ms. */
|
|
16
|
+
type RetryDecision = Readonly<{
|
|
17
|
+
delay?: number;
|
|
18
|
+
}>;
|
|
19
|
+
export type RetryPolicy = {
|
|
20
|
+
/** Decides whether failed attempt `attempt` (one-based) gets another attempt. `undefined` drops it. */
|
|
21
|
+
decide: (outcome: RateFailureOutcome, attempt: number) => RetryDecision | undefined;
|
|
22
|
+
};
|
|
23
|
+
/** Validates the retry options, then decides each failed attempt: drop, retry now, or retry after a delay. */
|
|
24
|
+
export declare function createRetryPolicy({ retry, retryBackoff, retryClassifier }: RetryPolicyOptions): RetryPolicy;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
const strategies = { fixed: true, linear: true, exponential: true };
|
|
2
|
+
const retryNow = Object.freeze({});
|
|
3
|
+
function validate(retry, retryBackoff) {
|
|
4
|
+
if (!Number.isInteger(retry) || retry < 0) {
|
|
5
|
+
throw new Error("retry must be a non-negative integer");
|
|
6
|
+
}
|
|
7
|
+
if (retryBackoff === undefined)
|
|
8
|
+
return;
|
|
9
|
+
if (!Object.hasOwn(strategies, retryBackoff.strategy)) {
|
|
10
|
+
throw new Error("retryBackoff.strategy must be fixed, linear, or exponential");
|
|
11
|
+
}
|
|
12
|
+
if (!Number.isFinite(retryBackoff.baseDelay) || retryBackoff.baseDelay < 0) {
|
|
13
|
+
throw new Error("retryBackoff.baseDelay must be a finite non-negative number");
|
|
14
|
+
}
|
|
15
|
+
if (retryBackoff.maxDelay !== undefined && (!Number.isFinite(retryBackoff.maxDelay) || retryBackoff.maxDelay < 0)) {
|
|
16
|
+
throw new Error("retryBackoff.maxDelay must be a finite non-negative number");
|
|
17
|
+
}
|
|
18
|
+
if (retryBackoff.jitter !== undefined && (!Number.isFinite(retryBackoff.jitter) || retryBackoff.jitter < 0 || retryBackoff.jitter > 1)) {
|
|
19
|
+
throw new Error("retryBackoff.jitter must be a finite number from 0 through 1");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function readRandom(random) {
|
|
23
|
+
try {
|
|
24
|
+
// eslint-disable-next-line sonarjs/pseudo-random -- Default jitter requires a random source.
|
|
25
|
+
const value = random?.() ?? Math.random();
|
|
26
|
+
return Number.isFinite(value) && value >= 0 && value <= 1 ? value : undefined;
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
return undefined;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
function calculateRetryDelay(policy, retryIndex) {
|
|
33
|
+
let delay;
|
|
34
|
+
switch (policy.strategy) {
|
|
35
|
+
case "linear":
|
|
36
|
+
delay = policy.baseDelay * retryIndex;
|
|
37
|
+
break;
|
|
38
|
+
case "exponential":
|
|
39
|
+
delay = policy.baseDelay * 2 ** (retryIndex - 1);
|
|
40
|
+
break;
|
|
41
|
+
default: delay = policy.baseDelay;
|
|
42
|
+
}
|
|
43
|
+
const cappedDelay = policy.maxDelay === undefined ? delay : Math.min(delay, policy.maxDelay);
|
|
44
|
+
if (policy.jitter === undefined)
|
|
45
|
+
return cappedDelay;
|
|
46
|
+
const random = readRandom(policy.random);
|
|
47
|
+
if (random === undefined)
|
|
48
|
+
return cappedDelay;
|
|
49
|
+
const jitteredDelay = cappedDelay * (1 + (random * 2 - 1) * policy.jitter);
|
|
50
|
+
return policy.maxDelay === undefined ? jitteredDelay : Math.min(jitteredDelay, policy.maxDelay);
|
|
51
|
+
}
|
|
52
|
+
/** Validates the retry options, then decides each failed attempt: drop, retry now, or retry after a delay. */
|
|
53
|
+
export function createRetryPolicy({ retry = 0, retryBackoff, retryClassifier }) {
|
|
54
|
+
validate(retry, retryBackoff);
|
|
55
|
+
function isRetryable(outcome, attempt) {
|
|
56
|
+
if (!retryClassifier)
|
|
57
|
+
return true;
|
|
58
|
+
try {
|
|
59
|
+
return retryClassifier(outcome, attempt) === true;
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return {
|
|
66
|
+
decide(outcome, attempt) {
|
|
67
|
+
if (attempt > retry || !isRetryable(outcome, attempt))
|
|
68
|
+
return undefined;
|
|
69
|
+
return retryBackoff === undefined ? retryNow : { delay: calculateRetryDelay(retryBackoff, attempt) };
|
|
70
|
+
},
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=retry-policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry-policy.js","sourceRoot":"","sources":["../src/retry-policy.ts"],"names":[],"mappings":"AA0BA,MAAM,UAAU,GAAqD,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;AACtH,MAAM,QAAQ,GAAkB,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;AAElD,SAAS,QAAQ,CAAC,KAAa,EAAE,YAAsC;IACrE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC1C,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IACD,IAAI,YAAY,KAAK,SAAS;QAAE,OAAO;IACvC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,YAAY,CAAC,QAAQ,CAAC,EAAE,CAAC;QACtD,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,YAAY,CAAC,SAAS,CAAC,IAAI,YAAY,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;QAC3E,MAAM,IAAI,KAAK,CAAC,6DAA6D,CAAC,CAAC;IACjF,CAAC;IACD,IAAI,YAA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AAY,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,mBAAmB,CAAC,YAAY,EAAE,OAAO,CAAC,EAAE,CAAC;QACvG,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/scheduler.d.ts
CHANGED
|
@@ -1,3 +1,36 @@
|
|
|
1
1
|
import type { AdaptiveRateOptions } from "./adaptive-rate.js";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type { PendingWorkOptions } from "./pending-work.js";
|
|
3
|
+
import type { RetryPolicy } from "./retry-policy.js";
|
|
4
|
+
export type ExecutionContext = Readonly<{
|
|
5
|
+
signal: AbortSignal;
|
|
6
|
+
}>;
|
|
7
|
+
/** Return `false` to signal failure (increments error count, triggers retry if configured). */
|
|
8
|
+
export type ThrottleCallback = (context: ExecutionContext) => boolean | void | Promise<boolean | void>;
|
|
9
|
+
export type ThrottleFn = (callback: ThrottleCallback) => void;
|
|
10
|
+
export type QueueLifecycleState = "running" | "paused" | "stopped" | "aborted" | "failed";
|
|
11
|
+
export type QueueState = Readonly<{
|
|
12
|
+
rate: number;
|
|
13
|
+
pending: number;
|
|
14
|
+
active: number;
|
|
15
|
+
state: QueueLifecycleState;
|
|
16
|
+
started: number;
|
|
17
|
+
succeeded: number;
|
|
18
|
+
failed: number;
|
|
19
|
+
retried: number;
|
|
20
|
+
rateIncreases: number;
|
|
21
|
+
rateDecreases: number;
|
|
22
|
+
}>;
|
|
23
|
+
export type ThrottleHandle = ThrottleFn & {
|
|
24
|
+
pause: () => void;
|
|
25
|
+
resume: () => void;
|
|
26
|
+
stop: () => void;
|
|
27
|
+
abort: () => void;
|
|
28
|
+
waitForIdle: () => Promise<void>;
|
|
29
|
+
getState: () => QueueState;
|
|
30
|
+
readonly pending: number;
|
|
31
|
+
};
|
|
32
|
+
export type SchedulerOptions = PendingWorkOptions & {
|
|
33
|
+
/** Most callbacks awaiting asynchronous settlement at once. */
|
|
34
|
+
concurrency: number;
|
|
35
|
+
};
|
|
36
|
+
export declare function createScheduler(options: SchedulerOptions, adaptiveRateOptions: AdaptiveRateOptions, retryPolicy: RetryPolicy): ThrottleHandle;
|
package/dist/scheduler.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createAdaptiveRate } from "./adaptive-rate.js";
|
|
2
2
|
import { createPendingWork } from "./pending-work.js";
|
|
3
|
-
import { calculateRetryDelay } from "./retry-backoff.js";
|
|
4
3
|
/** The state each event leads to. An event missing from the current state's row is a no-op. */
|
|
5
4
|
const lifecycleTransitions = {
|
|
6
5
|
running: { pause: "paused", stop: "stopped", abort: "aborted", fail: "failed" },
|
|
@@ -9,40 +8,31 @@ const lifecycleTransitions = {
|
|
|
9
8
|
aborted: {},
|
|
10
9
|
failed: {},
|
|
11
10
|
};
|
|
12
|
-
export function createScheduler(options, adaptiveRateOptions) {
|
|
13
|
-
const {
|
|
14
|
-
let last_called = 0;
|
|
15
|
-
let timeout;
|
|
11
|
+
export function createScheduler(options, adaptiveRateOptions, retryPolicy) {
|
|
12
|
+
const { concurrency, ...pendingWorkOptions } = options;
|
|
16
13
|
let lifecycle = { state: "running" };
|
|
17
14
|
let cnt_started = 0;
|
|
18
15
|
let cnt_succeeded = 0;
|
|
19
16
|
let cnt_failed = 0;
|
|
20
17
|
let cnt_retried = 0;
|
|
21
18
|
const abortController = new AbortController();
|
|
22
|
-
const
|
|
23
|
-
const work = createPendingWork({ capacity: maxQueueSize ?? Infinity, compactThreshold: compact_threshold }, { retryQueued: start });
|
|
19
|
+
const work = createPendingWork(pendingWorkOptions, { retryQueued: start });
|
|
24
20
|
const adaptiveRate = createAdaptiveRate(adaptiveRateOptions, {
|
|
25
21
|
hasPendingWork: () => work.queued > 0,
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
idle() {
|
|
36
|
-
clearTimeout(timeout);
|
|
37
|
-
timeout = undefined;
|
|
22
|
+
startsDue(limit) {
|
|
23
|
+
const batch = Math.min(limit, work.queued);
|
|
24
|
+
for (let started = 0; started < batch && work.active < concurrency; started++) {
|
|
25
|
+
const item = work.take();
|
|
26
|
+
if (item === undefined)
|
|
27
|
+
break;
|
|
28
|
+
execute(item);
|
|
29
|
+
}
|
|
30
|
+
return work.active < concurrency;
|
|
38
31
|
},
|
|
39
32
|
failed(error) {
|
|
40
33
|
transition("fail", error);
|
|
41
34
|
},
|
|
42
35
|
});
|
|
43
|
-
function spacing() {
|
|
44
|
-
return evenly_spaced ? interval / adaptiveRate.rate : interval;
|
|
45
|
-
}
|
|
46
36
|
/** Moves the lifecycle for `event` and runs the cleanup that entering the new state requires. */
|
|
47
37
|
function transition(event, error) {
|
|
48
38
|
const next = lifecycleTransitions[lifecycle.state][event];
|
|
@@ -72,24 +62,14 @@ export function createScheduler(options, adaptiveRateOptions) {
|
|
|
72
62
|
work.fail(error);
|
|
73
63
|
}
|
|
74
64
|
}
|
|
75
|
-
function isRetryable(item, outcome) {
|
|
76
|
-
if (!outcome || item.retries === 0)
|
|
77
|
-
return false;
|
|
78
|
-
try {
|
|
79
|
-
return retryClassifier ? retryClassifier(outcome, retry - item.retries + 1) === true : true;
|
|
80
|
-
}
|
|
81
|
-
catch {
|
|
82
|
-
return true;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
65
|
function nextAttempt(item, outcome) {
|
|
86
|
-
if (!
|
|
66
|
+
if (!outcome)
|
|
67
|
+
return undefined;
|
|
68
|
+
const decision = retryPolicy.decide(outcome, item.attempt);
|
|
69
|
+
if (!decision)
|
|
87
70
|
return undefined;
|
|
88
71
|
cnt_retried++;
|
|
89
|
-
|
|
90
|
-
if (retryBackoff === undefined)
|
|
91
|
-
return { item: retryItem };
|
|
92
|
-
return { item: retryItem, delay: calculateRetryDelay(retryBackoff, retry - item.retries + 1) };
|
|
72
|
+
return { item: { fn: item.fn, attempt: item.attempt + 1 }, ...decision };
|
|
93
73
|
}
|
|
94
74
|
function handleSettlement(item, outcome, reportSettlement, resume = false) {
|
|
95
75
|
if (lifecycle.state === "aborted" || lifecycle.state === "failed") {
|
|
@@ -102,8 +82,9 @@ export function createScheduler(options, adaptiveRateOptions) {
|
|
|
102
82
|
cnt_succeeded++;
|
|
103
83
|
work.settle(() => nextAttempt(item, outcome), () => {
|
|
104
84
|
reportSettlement(outcome);
|
|
105
|
-
|
|
106
|
-
|
|
85
|
+
// An async settlement frees a slot; a start may be due if concurrency held one back.
|
|
86
|
+
if (resume)
|
|
87
|
+
start();
|
|
107
88
|
});
|
|
108
89
|
}
|
|
109
90
|
function execute(item) {
|
|
@@ -123,30 +104,6 @@ export function createScheduler(options, adaptiveRateOptions) {
|
|
|
123
104
|
}
|
|
124
105
|
handleSettlement(item, result === false ? { kind: "returned-false" } : undefined, reportSettlement);
|
|
125
106
|
}
|
|
126
|
-
function dequeue() {
|
|
127
|
-
const threshold = last_called + spacing();
|
|
128
|
-
const now = Date.now();
|
|
129
|
-
if (now < threshold) {
|
|
130
|
-
clearTimeout(timeout);
|
|
131
|
-
timeout = setTimeout(dequeue, threshold - now);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
const batch = Math.min(evenly_spaced ? 1 : adaptiveRate.rate, work.queued);
|
|
135
|
-
let started = 0;
|
|
136
|
-
while (started < batch && work.active < max_concurrency) {
|
|
137
|
-
const item = work.take();
|
|
138
|
-
if (item === undefined)
|
|
139
|
-
break;
|
|
140
|
-
if (started++ === 0)
|
|
141
|
-
last_called = Date.now();
|
|
142
|
-
execute(item);
|
|
143
|
-
}
|
|
144
|
-
if (work.queued === 0)
|
|
145
|
-
adaptiveRate.drained();
|
|
146
|
-
if (adaptiveRate.pacing !== "open" || work.active >= max_concurrency)
|
|
147
|
-
return;
|
|
148
|
-
timeout = setTimeout(dequeue, spacing());
|
|
149
|
-
}
|
|
150
107
|
function start() {
|
|
151
108
|
if (lifecycle.state === "running")
|
|
152
109
|
adaptiveRate.start();
|
|
@@ -156,7 +113,7 @@ export function createScheduler(options, adaptiveRateOptions) {
|
|
|
156
113
|
throw new Error("Cannot enqueue work after the queue has been aborted");
|
|
157
114
|
if (lifecycle.state === "failed")
|
|
158
115
|
throw lifecycle.error;
|
|
159
|
-
work.accept({ fn: callback,
|
|
116
|
+
work.accept({ fn: callback, attempt: 1 });
|
|
160
117
|
if (lifecycle.state === "stopped")
|
|
161
118
|
transition("restart");
|
|
162
119
|
else
|
package/dist/scheduler.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,2BAA2B;
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,2BAA2B;AAExD,OAAO,EAAE,iBAAiB,EAAE,0BAA0B;AA8CtD,+FAA+F;AAC/F,MAAM,oBAAoB,GAA0G;IAClI,OAAO,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE;IAC/E,MAAM,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;IAChE,OAAO,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE;IACjD,OAAO,EAAE,EAAE;IACX,MAAM,EAAE,EAAE;CACX,CAAC;AAOF,MAAM,UAAU,eAAe,CAAC,OAAyB,EAAE,mBAAwC,EAAE,WAAwB;IAC3H,MAAM,EAAE,WAAW,EAAE,GAAG,kBAAkB,EAAE,GAAG,OAAO,CAAC;IACvD,IAAI,SAAS,GAAc,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;IAChD,IAAI,WAAW,G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M,CAAC,MAAM,CAAC;QACjD,IAAI,EAAE,YAAY,CAAC,IAAI;QACvB,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,KAAK,EAAE,SAAS,CAAC,KAAK;QACtB,OAAO,EAAE,WAAW;QACpB,SAAS,EAAE,aAAa;QACxB,MAAM,EAAE,UAAU;QAClB,OAAO,EAAE,WAAW;QACpB,aAAa,EAAE,YAAY,CAAC,aAAa;QACzC,aAAa,EAAE,YAAY,CAAC,aAAa;KAC1C,CAAC,CAAC;IACH,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,SAAS,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IACvE,OAAO,OAAyB,CAAC;AACnC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dynamic-throttled-queue",
|
|
3
|
-
"version": "2.3.0-rc.
|
|
3
|
+
"version": "2.3.0-rc.477ab9c",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Dynamically throttles arbitrary code to execute between a minimum and maximum number of times per interval. Best for making throttled API requests.",
|
|
6
6
|
"files": [
|
|
@@ -30,19 +30,20 @@
|
|
|
30
30
|
"url": "https://github.com/adrianbrowning/dynamic-throttled-queue/issues"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
|
-
"@commitlint/cli": "
|
|
33
|
+
"@commitlint/cli": "21.2.3",
|
|
34
34
|
"@commitlint/config-conventional": "20.0.0",
|
|
35
|
-
"@gingacodemonkey/config": "^0.0.
|
|
35
|
+
"@gingacodemonkey/config": "^0.0.38",
|
|
36
36
|
"@types/node": "^24.13.3",
|
|
37
|
+
"@varlock/bumpy": "^1.18.1",
|
|
37
38
|
"eslint": "^9.39.5",
|
|
38
|
-
"husky": "9.
|
|
39
|
+
"husky": "9.1.7",
|
|
39
40
|
"jscpd": "^4.2.5",
|
|
40
41
|
"knip": "5.70.1",
|
|
41
|
-
"lint-staged": "
|
|
42
|
+
"lint-staged": "17.6.0",
|
|
42
43
|
"only-allow": "^1.2.2",
|
|
43
44
|
"typescript": "^6.0.3",
|
|
44
|
-
"vitest": "^
|
|
45
|
-
"zshy": "^0.
|
|
45
|
+
"vitest": "^5.0.2",
|
|
46
|
+
"zshy": "^0.8.0"
|
|
46
47
|
},
|
|
47
48
|
"engines": {
|
|
48
49
|
"node": ">=24.0.0",
|
|
@@ -56,9 +57,6 @@
|
|
|
56
57
|
"default": "./dist/dynamic-throttled-queue.js"
|
|
57
58
|
}
|
|
58
59
|
},
|
|
59
|
-
"dependencies": {
|
|
60
|
-
"@varlock/bumpy": "^1.18.1"
|
|
61
|
-
},
|
|
62
60
|
"scripts": {
|
|
63
61
|
"build": "zshy",
|
|
64
62
|
"test": "vitest run",
|
package/dist/retry-backoff.d.ts
DELETED
package/dist/retry-backoff.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
function readRandom(random) {
|
|
2
|
-
try {
|
|
3
|
-
// eslint-disable-next-line sonarjs/pseudo-random -- Default jitter requires a random source.
|
|
4
|
-
const value = random?.() ?? Math.random();
|
|
5
|
-
return Number.isFinite(value) && value >= 0 && value <= 1 ? value : undefined;
|
|
6
|
-
}
|
|
7
|
-
catch {
|
|
8
|
-
return undefined;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export function calculateRetryDelay(policy, retryIndex) {
|
|
12
|
-
let delay;
|
|
13
|
-
switch (policy.strategy) {
|
|
14
|
-
case "linear":
|
|
15
|
-
delay = policy.baseDelay * retryIndex;
|
|
16
|
-
break;
|
|
17
|
-
case "exponential":
|
|
18
|
-
delay = policy.baseDelay * 2 ** (retryIndex - 1);
|
|
19
|
-
break;
|
|
20
|
-
default: delay = policy.baseDelay;
|
|
21
|
-
}
|
|
22
|
-
const cappedDelay = policy.maxDelay === undefined ? delay : Math.min(delay, policy.maxDelay);
|
|
23
|
-
if (policy.jitter === undefined)
|
|
24
|
-
return cappedDelay;
|
|
25
|
-
const random = readRandom(policy.random);
|
|
26
|
-
if (random === undefined)
|
|
27
|
-
return cappedDelay;
|
|
28
|
-
const jitteredDelay = cappedDelay * (1 + (random * 2 - 1) * policy.jitter);
|
|
29
|
-
return policy.maxDelay === undefined ? jitteredDelay : Math.min(jitteredDelay, policy.maxDelay);
|
|
30
|
-
}
|
|
31
|
-
//# sourceMappingURL=retry-backoff.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"retry-backoff.js","sourceRoot":"","sources":["../src/retry-backoff.ts"],"names":[],"mappings":"AAEA,SAAS,UAAU,CAAC,MAAkC;IACpD,IAAI,CAAC;QACH,6FAA6F;QAC7F,MAAM,KAAK,GAAG,MAAM,EAAE,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;QAC1C,OAAO,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAChF,CAAC;IACD,MAAM,CAAC;QACL,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAoB,EAAE,UAAkB;IAC1E,IAAI,KAAa,CAAC;IAClB,QAAQ,MAAM,CAAC,QAAQ,EAAE,CAAC;QACxB,KAAK,QAAQ;YAAE,KAAK,GAAG,MAAM,CAAC,SAAS,GAAG,UAAU,CAAC;YAAC,MAAM;QAC5D,KAAK,aAAa;YAAE,KAAK,GAAG,MAAM,CAAC,SAAS,GAAG,CAAC,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,CAAC;YAAC,MAAM;QAC5E,OAAO,CAAC,CAAC,KAAK,GAAG,MAAM,CAAC,SAAS,CAAC;IACpC,CAAC;IACD,MAAM,WAAW,GAAG,MAAM,CAAC,QAAQ,KAAK,SAAS,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