@factorearth/recordmiddleware-errorhandler 0.0.1-y.16 → 0.0.1-y.22
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/package.json +5 -3
- package/dist/backOff.d.ts +0 -28
- package/dist/backOff.js +0 -36
- package/dist/delay.d.ts +0 -7
- package/dist/delay.js +0 -9
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/lib/backOff.ts +0 -55
- package/lib/delay.ts +0 -9
- package/lib/index.ts +0 -1
- package/tsconfig.json +0 -27
package/package.json
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@factorearth/recordmiddleware-errorhandler",
|
|
3
|
-
"version": "0.0.1-y.
|
|
3
|
+
"version": "0.0.1-y.22",
|
|
4
4
|
"description": "A module for handling CRUD errors in lambda",
|
|
5
5
|
"author": "madtrx <marlin.makori@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/FactorEarth/RecordMiddleware#readme",
|
|
7
7
|
"license": "ISC",
|
|
8
8
|
"main": "dist/index.js",
|
|
9
9
|
"types": "dist/index.d.ts",
|
|
10
|
-
"
|
|
10
|
+
"files": [
|
|
11
|
+
"dist"
|
|
12
|
+
],
|
|
11
13
|
"repository": {
|
|
12
14
|
"type": "git",
|
|
13
15
|
"url": "git+https://github.com/FactorEarth/RecordMiddleware.git"
|
|
@@ -22,5 +24,5 @@
|
|
|
22
24
|
"access": "public",
|
|
23
25
|
"registry": "https://registry.npmjs.org/"
|
|
24
26
|
},
|
|
25
|
-
"gitHead": "
|
|
27
|
+
"gitHead": "a259809dbea65ff3fb42b5ead58aa37648c83a02"
|
|
26
28
|
}
|
package/dist/backOff.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
interface BackoffOptions {
|
|
2
|
-
/**
|
|
3
|
-
* The initial delay you want to apply. Default to 100ms
|
|
4
|
-
*/
|
|
5
|
-
delay?: number;
|
|
6
|
-
/**
|
|
7
|
-
* The number of times you want to attempt the function. Default 10
|
|
8
|
-
*/
|
|
9
|
-
numberOfAttempts?: number;
|
|
10
|
-
/**
|
|
11
|
-
* An optional max delay
|
|
12
|
-
*/
|
|
13
|
-
maxDelay?: number;
|
|
14
|
-
/**
|
|
15
|
-
* An initial multiplier to be taken to the power of the attempt number when deciding how long to wait. Default value of 2
|
|
16
|
-
*/
|
|
17
|
-
timeMultiple?: number;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Given a task, attempts to execute it a designated number of times, returning the eventual response
|
|
21
|
-
* @author Eric Webb <ewebb@factorearth.com>
|
|
22
|
-
* @param task The task we want to retry potentially
|
|
23
|
-
* @param evaluator A function to evaluate if the task executed successfully, or if it needs to be retried. Needs to return boolean
|
|
24
|
-
* @param options The configurable options for the module
|
|
25
|
-
* @returns The result of the function
|
|
26
|
-
*/
|
|
27
|
-
export declare function backoff<TaskResult, TaskArguments extends any[]>(task: (...args: TaskArguments) => Promise<TaskResult>, evaluator: (taskResult: TaskResult) => boolean, options?: BackoffOptions, ...taskArguments: TaskArguments): Promise<TaskResult | void>;
|
|
28
|
-
export {};
|
package/dist/backOff.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { delay } from "./delay";
|
|
2
|
-
// Default values
|
|
3
|
-
const DELAY = 100;
|
|
4
|
-
const NUMBER_OF_ATTEMPTS = 10;
|
|
5
|
-
const MAX_DELAY = Infinity;
|
|
6
|
-
const TIME_MULTIPLE = 2;
|
|
7
|
-
/**
|
|
8
|
-
* Given a task, attempts to execute it a designated number of times, returning the eventual response
|
|
9
|
-
* @author Eric Webb <ewebb@factorearth.com>
|
|
10
|
-
* @param task The task we want to retry potentially
|
|
11
|
-
* @param evaluator A function to evaluate if the task executed successfully, or if it needs to be retried. Needs to return boolean
|
|
12
|
-
* @param options The configurable options for the module
|
|
13
|
-
* @returns The result of the function
|
|
14
|
-
*/
|
|
15
|
-
export async function backoff(task, evaluator, options, ...taskArguments) {
|
|
16
|
-
let attemptNumber = 0;
|
|
17
|
-
const maxAttempts = options?.numberOfAttempts || NUMBER_OF_ATTEMPTS;
|
|
18
|
-
const initialDelay = options?.delay || DELAY;
|
|
19
|
-
const maxDelay = options?.maxDelay || MAX_DELAY;
|
|
20
|
-
const timeMultiple = options?.timeMultiple || TIME_MULTIPLE;
|
|
21
|
-
while (attemptNumber < maxAttempts) {
|
|
22
|
-
const calculatedDelay = initialDelay * Math.pow(timeMultiple, attemptNumber);
|
|
23
|
-
const delayTime = Math.min(calculatedDelay, maxDelay);
|
|
24
|
-
await delay(delayTime);
|
|
25
|
-
try {
|
|
26
|
-
const taskResult = await task(...taskArguments);
|
|
27
|
-
const evaluatorResult = evaluator(taskResult);
|
|
28
|
-
if (evaluatorResult || !(attemptNumber + 1 < maxAttempts))
|
|
29
|
-
return taskResult;
|
|
30
|
-
}
|
|
31
|
-
catch (err) {
|
|
32
|
-
// recordSentry({ error: err, msg: "Error executing backoff task" });
|
|
33
|
-
}
|
|
34
|
-
attemptNumber++;
|
|
35
|
-
}
|
|
36
|
-
}
|
package/dist/delay.d.ts
DELETED
package/dist/delay.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a promise that resolvers after a provided number of ms
|
|
3
|
-
* @author Eric Webb <ewebb@factorearth.com>
|
|
4
|
-
* @param millis The number of ms you want to sleep
|
|
5
|
-
* @returns A void promise
|
|
6
|
-
*/
|
|
7
|
-
export function delay(millis) {
|
|
8
|
-
return new Promise((resolve, _reject) => setTimeout(resolve, millis));
|
|
9
|
-
}
|
package/dist/index.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./backOff";
|
package/dist/index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./backOff";
|
package/lib/backOff.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { delay } from "./delay";
|
|
2
|
-
|
|
3
|
-
interface BackoffOptions {
|
|
4
|
-
/**
|
|
5
|
-
* The initial delay you want to apply. Default to 100ms
|
|
6
|
-
*/
|
|
7
|
-
delay?: number;
|
|
8
|
-
/**
|
|
9
|
-
* The number of times you want to attempt the function. Default 10
|
|
10
|
-
*/
|
|
11
|
-
numberOfAttempts?: number;
|
|
12
|
-
/**
|
|
13
|
-
* An optional max delay
|
|
14
|
-
*/
|
|
15
|
-
maxDelay?: number;
|
|
16
|
-
/**
|
|
17
|
-
* An initial multiplier to be taken to the power of the attempt number when deciding how long to wait. Default value of 2
|
|
18
|
-
*/
|
|
19
|
-
timeMultiple?: number;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Default values
|
|
23
|
-
const DELAY = 100;
|
|
24
|
-
const NUMBER_OF_ATTEMPTS = 10;
|
|
25
|
-
const MAX_DELAY = Infinity;
|
|
26
|
-
const TIME_MULTIPLE = 2;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Given a task, attempts to execute it a designated number of times, returning the eventual response
|
|
30
|
-
* @author Eric Webb <ewebb@factorearth.com>
|
|
31
|
-
* @param task The task we want to retry potentially
|
|
32
|
-
* @param evaluator A function to evaluate if the task executed successfully, or if it needs to be retried. Needs to return boolean
|
|
33
|
-
* @param options The configurable options for the module
|
|
34
|
-
* @returns The result of the function
|
|
35
|
-
*/
|
|
36
|
-
export async function backoff<TaskResult, TaskArguments extends any[]>(task: (...args: TaskArguments) => Promise<TaskResult>, evaluator: (taskResult: TaskResult) => boolean, options?: BackoffOptions, ...taskArguments: TaskArguments): Promise<TaskResult | void> {
|
|
37
|
-
let attemptNumber = 0;
|
|
38
|
-
const maxAttempts = options?.numberOfAttempts || NUMBER_OF_ATTEMPTS;
|
|
39
|
-
const initialDelay = options?.delay || DELAY;
|
|
40
|
-
const maxDelay = options?.maxDelay || MAX_DELAY;
|
|
41
|
-
const timeMultiple = options?.timeMultiple || TIME_MULTIPLE;
|
|
42
|
-
while (attemptNumber < maxAttempts) {
|
|
43
|
-
const calculatedDelay = initialDelay * Math.pow(timeMultiple, attemptNumber);
|
|
44
|
-
const delayTime = Math.min(calculatedDelay, maxDelay);
|
|
45
|
-
await delay(delayTime);
|
|
46
|
-
try {
|
|
47
|
-
const taskResult: TaskResult = await task(...taskArguments);
|
|
48
|
-
const evaluatorResult = evaluator(taskResult);
|
|
49
|
-
if (evaluatorResult || !(attemptNumber + 1 < maxAttempts)) return taskResult;
|
|
50
|
-
} catch (err) {
|
|
51
|
-
// recordSentry({ error: err, msg: "Error executing backoff task" });
|
|
52
|
-
}
|
|
53
|
-
attemptNumber++;
|
|
54
|
-
}
|
|
55
|
-
}
|
package/lib/delay.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Creates a promise that resolvers after a provided number of ms
|
|
3
|
-
* @author Eric Webb <ewebb@factorearth.com>
|
|
4
|
-
* @param millis The number of ms you want to sleep
|
|
5
|
-
* @returns A void promise
|
|
6
|
-
*/
|
|
7
|
-
export function delay(millis: number): Promise<any> {
|
|
8
|
-
return new Promise((resolve, _reject) => setTimeout(resolve, millis));
|
|
9
|
-
}
|
package/lib/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./backOff"
|
package/tsconfig.json
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"baseUrl": "lib",
|
|
4
|
-
"rootDir": "lib",
|
|
5
|
-
"outDir": "dist",
|
|
6
|
-
"target": "ESNext",
|
|
7
|
-
"types": [
|
|
8
|
-
"node"
|
|
9
|
-
],
|
|
10
|
-
"lib": [
|
|
11
|
-
"ESNext",
|
|
12
|
-
"DOM",
|
|
13
|
-
"DOM.Iterable"
|
|
14
|
-
],
|
|
15
|
-
"module": "ESNext",
|
|
16
|
-
"moduleResolution": "node",
|
|
17
|
-
"skipLibCheck": true,
|
|
18
|
-
"strict": true,
|
|
19
|
-
"esModuleInterop": true,
|
|
20
|
-
"forceConsistentCasingInFileNames": true,
|
|
21
|
-
"declaration": true,
|
|
22
|
-
"allowJs": true,
|
|
23
|
-
"resolveJsonModule": true,
|
|
24
|
-
},
|
|
25
|
-
"include": ["lib/**/*.d.ts", "lib/**/*.ts", "lib/**/*.tsx"],
|
|
26
|
-
"exclude": ["node_modules", "./**/*.test.tsx"]
|
|
27
|
-
}
|