@creejs/commons-retrier 2.1.6 → 2.1.8
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/dist/cjs/index-dev.cjs +201 -23
- package/dist/cjs/index-dev.cjs.map +1 -1
- package/dist/cjs/index-min.cjs +1 -1
- package/dist/cjs/index-min.cjs.map +1 -1
- package/dist/esm/index-dev.js +199 -24
- package/dist/esm/index-dev.js.map +1 -1
- package/dist/esm/index-min.js +1 -1
- package/dist/esm/index-min.js.map +1 -1
- package/dist/umd/index.dev.js +201 -23
- package/dist/umd/index.dev.js.map +1 -1
- package/dist/umd/index.min.js +1 -1
- package/dist/umd/index.min.js.map +1 -1
- package/package.json +3 -3
- package/types/index.d.ts +6 -0
- package/types/policy/exponential-backoff.d.ts +12 -0
- package/types/policy/fixed-backoff.d.ts +13 -0
- package/types/policy/linear-backoff.d.ts +13 -0
- package/types/policy.d.ts +15 -5
- package/types/retrier-factory.d.ts +23 -0
- package/types/retrier.d.ts +20 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class FixedBackoff
|
|
3
|
+
*/
|
|
4
|
+
export default class FixedBackoff extends FixedInterval {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a fixed backoff policy with optional jitter.
|
|
7
|
+
* @param {number} fixedInterval - The fixed interval between retries in milliseconds.
|
|
8
|
+
* @param {number} [jitter=500] - The maximum random jitter to add to the interval in milliseconds.
|
|
9
|
+
*/
|
|
10
|
+
constructor(fixedInterval: number, jitter?: number);
|
|
11
|
+
}
|
|
12
|
+
export { FixedBackoff as FixedBackoffType };
|
|
13
|
+
import FixedInterval from './fixed-interval-policy.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class LinearBackoff
|
|
3
|
+
*/
|
|
4
|
+
export default class LinearBackoff extends FixedIncreasePolicy {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a linear backoff policy with optional jitter.
|
|
7
|
+
* @param {number} increasement - The base increasement value for backoff.
|
|
8
|
+
* @param {number} [jitter=500] - The maximum jitter value to add to backoff (default: 500).
|
|
9
|
+
*/
|
|
10
|
+
constructor(increasement: number, jitter?: number);
|
|
11
|
+
}
|
|
12
|
+
export { LinearBackoff as LinearBackoffType };
|
|
13
|
+
import FixedIncreasePolicy from './fixed-increase-policy.js';
|
package/types/policy.d.ts
CHANGED
|
@@ -2,11 +2,16 @@ export default class Policy {
|
|
|
2
2
|
_min: number;
|
|
3
3
|
_max: number;
|
|
4
4
|
_nextInterval: number;
|
|
5
|
+
_jitter: number;
|
|
6
|
+
set jitter(jitter: number);
|
|
7
|
+
get jitter(): number;
|
|
5
8
|
/**
|
|
6
9
|
* Copies settings to target policy.
|
|
10
|
+
* 1. range
|
|
11
|
+
* 2. nextInterval value
|
|
7
12
|
* @param {Policy} targetPolicy - The policy to modify.
|
|
8
13
|
*/
|
|
9
|
-
|
|
14
|
+
copyPolicySettingTo(targetPolicy: Policy): void;
|
|
10
15
|
/**
|
|
11
16
|
* Sets a fixed interval retry policy.
|
|
12
17
|
}
|
|
@@ -37,16 +42,21 @@ export default class Policy {
|
|
|
37
42
|
reset(): this;
|
|
38
43
|
/**
|
|
39
44
|
* Interval ms of next execution
|
|
45
|
+
* @param {number} retries current retry times
|
|
40
46
|
* @returns {number}
|
|
41
|
-
* @throws {Error} Always throws "Not Implemented Yet" error.
|
|
42
47
|
*/
|
|
43
|
-
generate(): number;
|
|
44
|
-
|
|
48
|
+
generate(retries: number): number;
|
|
49
|
+
/**
|
|
50
|
+
* @param {number} retries current retry times
|
|
51
|
+
* @returns {number}
|
|
52
|
+
*/
|
|
53
|
+
_increase(retries: number): number;
|
|
45
54
|
/**
|
|
46
55
|
* subclass should implement this method
|
|
56
|
+
* @param {number} retries current retry times
|
|
47
57
|
* @returns {number} The interval in milliseconds to wait before the next retry attempt.
|
|
48
58
|
* @protected
|
|
49
59
|
*/
|
|
50
|
-
protected _next(): number;
|
|
60
|
+
protected _next(retries: number): number;
|
|
51
61
|
}
|
|
52
62
|
export { Policy as PolicyType };
|
|
@@ -7,8 +7,11 @@ declare namespace _default {
|
|
|
7
7
|
export { max };
|
|
8
8
|
export { range };
|
|
9
9
|
export { fixedInterval };
|
|
10
|
+
export { fixedBackoff };
|
|
10
11
|
export { fixedIncrease };
|
|
12
|
+
export { linearBackoff };
|
|
11
13
|
export { factorIncrease };
|
|
14
|
+
export { exponentialBackoff };
|
|
12
15
|
export { shuttleInterval };
|
|
13
16
|
export { timeout };
|
|
14
17
|
export { taskTimeout };
|
|
@@ -63,18 +66,38 @@ export function range(min: number, max: number): Retrier;
|
|
|
63
66
|
* @returns {Retrier} A new Retrier instance configured with the specified fixed interval.
|
|
64
67
|
*/
|
|
65
68
|
export function fixedInterval(fixedInterval: number): Retrier;
|
|
69
|
+
/**
|
|
70
|
+
* Creates a retrier with a fixed backoff strategy.
|
|
71
|
+
* @param {number} fixedInterval - The fixed interval between retries in milliseconds.
|
|
72
|
+
* @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
|
|
73
|
+
* @returns {Retrier} A retrier instance configured with fixed backoff.
|
|
74
|
+
*/
|
|
75
|
+
export function fixedBackoff(fixedInterval: number, jitter?: number): Retrier;
|
|
66
76
|
/**
|
|
67
77
|
* Creates a retrier with a fixed increase strategy.
|
|
68
78
|
* @param {number} increasement - The fixed amount to increase on each retry.
|
|
69
79
|
* @returns {Retrier} A retrier instance configured with fixed increase.
|
|
70
80
|
*/
|
|
71
81
|
export function fixedIncrease(increasement: number): Retrier;
|
|
82
|
+
/**
|
|
83
|
+
* Creates a retrier with a fixed increase strategy.
|
|
84
|
+
* @param {number} increasement - The fixed amount to increase on each retry.
|
|
85
|
+
* @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
|
|
86
|
+
* @returns {Retrier} A retrier instance configured with fixed increase.
|
|
87
|
+
*/
|
|
88
|
+
export function linearBackoff(increasement: number, jitter?: number): Retrier;
|
|
72
89
|
/**
|
|
73
90
|
* Creates a new Retrier instance with factor-increase strategy.
|
|
74
91
|
* @param {number} factor - The factor by which to increase the interval on each retry.
|
|
75
92
|
* @returns {Retrier} A new Retrier instance with factor-increase strategy.
|
|
76
93
|
*/
|
|
77
94
|
export function factorIncrease(factor: number): Retrier;
|
|
95
|
+
/**
|
|
96
|
+
* Creates a new Retrier instance with exponential-backoff strategy.
|
|
97
|
+
* @param {number} [jitter=500]
|
|
98
|
+
* @returns {Retrier} A new Retrier instance
|
|
99
|
+
*/
|
|
100
|
+
export function exponentialBackoff(jitter?: number): Retrier;
|
|
78
101
|
/**
|
|
79
102
|
* Creates a Retrier instance with a shuttle-interval strategt.
|
|
80
103
|
* @param {number} stepLength - The interval step length of each change
|
package/types/retrier.d.ts
CHANGED
|
@@ -98,18 +98,38 @@ export default class Retrier {
|
|
|
98
98
|
* @returns {Retrier} The Retrier instance for chaining.
|
|
99
99
|
*/
|
|
100
100
|
fixedInterval(fixedInterval: number): Retrier;
|
|
101
|
+
/**
|
|
102
|
+
* sets a fixed backoff strategy.
|
|
103
|
+
* @param {number} fixedInterval - The fixed interval between retries in milliseconds.
|
|
104
|
+
* @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
|
|
105
|
+
* @returns {Retrier} A retrier instance configured with fixed backoff.
|
|
106
|
+
*/
|
|
107
|
+
fixedBackoff(fixedInterval: number, jitter?: number): Retrier;
|
|
101
108
|
/**
|
|
102
109
|
* Sets a fixed increase policy for retry intervals.
|
|
103
110
|
* @param {number} increasement - The fixed amount to increase the interval by on each retry.
|
|
104
111
|
* @returns {this} The retrier instance for chaining.
|
|
105
112
|
*/
|
|
106
113
|
fixedIncrease(increasement: number): this;
|
|
114
|
+
/**
|
|
115
|
+
* Sets a fixed increase policy for retry intervals.
|
|
116
|
+
* @param {number} increasement - The fixed amount to increase the interval by on each retry.
|
|
117
|
+
* @param {number} [jitter=500] - The maximum jitter to add to the interval in milliseconds.
|
|
118
|
+
* @returns {this} The retrier instance for chaining.
|
|
119
|
+
*/
|
|
120
|
+
linearBackoff(increasement: number, jitter?: number): this;
|
|
107
121
|
/**
|
|
108
122
|
* Sets a fixed increase factor for retry delays.
|
|
109
123
|
* @param {number} factor - The multiplier for delay increase between retries.
|
|
110
124
|
* @returns {this} The retrier instance for method chaining.
|
|
111
125
|
*/
|
|
112
126
|
factorIncrease(factor: number): this;
|
|
127
|
+
/**
|
|
128
|
+
* Creates a new Retrier instance with exponential-backoff strategy.
|
|
129
|
+
* @param {number} [jitter]
|
|
130
|
+
* @returns {Retrier} A new Retrier instance
|
|
131
|
+
*/
|
|
132
|
+
exponentialBackoff(jitter?: number): Retrier;
|
|
113
133
|
/**
|
|
114
134
|
* Sets a shuttle retry policy with the given step length.
|
|
115
135
|
* @param {number} stepLength - The interval between retry attempts.
|