@speedkit/cli 2.57.1 → 2.59.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 +15 -0
- package/README.md +1 -1
- package/dist/services/document-handler-runtime/document-handler-server.js +14 -15
- package/dist/services/onboarding/error/vm-empty-response-error.d.ts +5 -0
- package/dist/services/onboarding/error/vm-empty-response-error.js +12 -0
- package/dist/services/prewarm/assets/asset-api-client.d.ts +4 -0
- package/dist/services/prewarm/assets/asset-api-client.js +15 -1
- package/dist/services/prewarm/pre-warm-model.d.ts +2 -1
- package/dist/services/prewarm/pre-warm-model.js +3 -2
- package/dist/services/prewarm/pre-warm-service.js +3 -0
- package/oclif.manifest.json +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# [2.59.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.58.0...v2.59.0) (2024-10-08)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* **prewarm:** handle rateLimiter on retry ([b744295](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/b7442959fded70807d7d0d6ae4e58cc4afa756f3))
|
|
7
|
+
* **prewarm:** increase rateLimit after successfull batch ([d112927](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/d11292731b0151a0e467b595630673f452bdf845))
|
|
8
|
+
|
|
9
|
+
# [2.58.0](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.57.1...v2.58.0) (2024-09-27)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* throw error if response of local docHandler is empty ([61fa850](https://gitlab.orestes.info/baqend/speed-kit-cli/commit/61fa850077b983f6038f672b73f76c9b553aa2d3))
|
|
15
|
+
|
|
1
16
|
## [2.57.1](https://gitlab.orestes.info/baqend/speed-kit-cli/compare/v2.57.0...v2.57.1) (2024-09-26)
|
|
2
17
|
|
|
3
18
|
|
package/README.md
CHANGED
|
@@ -13,6 +13,8 @@ const files_1 = require("../../models/files");
|
|
|
13
13
|
const node_fetch_1 = tslib_1.__importDefault(require("node-fetch"));
|
|
14
14
|
const request_1 = require("./server/request");
|
|
15
15
|
const document_handler_response_1 = require("./server/document-handler-response");
|
|
16
|
+
const safe_1 = require("../../helpers/safe");
|
|
17
|
+
const vm_empty_response_error_1 = require("../onboarding/error/vm-empty-response-error");
|
|
16
18
|
class DocumentHandlerServer {
|
|
17
19
|
customerConfig;
|
|
18
20
|
files;
|
|
@@ -62,23 +64,20 @@ class DocumentHandlerServer {
|
|
|
62
64
|
const script = new vm.Script(this.documentHandlerConfigCode + this.getTransformFunctionWrapper(), {
|
|
63
65
|
filename: this.files.getByName("config_documentHandler").path,
|
|
64
66
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
}
|
|
76
|
-
catch (error) {
|
|
77
|
-
if (error instanceof Error) {
|
|
78
|
-
throw new vm_error_1.VmError(error.message);
|
|
67
|
+
const vmResponse = await (0, safe_1.safe)(new Promise((resolve, reject) => {
|
|
68
|
+
vmContext.skInternalResponse.resolve = resolve;
|
|
69
|
+
// @ts-expect-error reject is unknown
|
|
70
|
+
vmContext.reject = reject;
|
|
71
|
+
const context = vm.createContext(vmContext);
|
|
72
|
+
script.runInContext(context, { displayErrors: true });
|
|
73
|
+
}));
|
|
74
|
+
if (vmResponse.success === true) {
|
|
75
|
+
if (!vmResponse.data.body || vmResponse.data.body?.length === 0) {
|
|
76
|
+
throw new vm_empty_response_error_1.VmEmptyResponseError(`documentHandlerResponse is empty for url: ${url}`);
|
|
79
77
|
}
|
|
80
|
-
|
|
78
|
+
return vmResponse.data;
|
|
81
79
|
}
|
|
80
|
+
throw new vm_error_1.VmError(vmResponse.error + JSON.stringify(vmResponse.errorObj));
|
|
82
81
|
}
|
|
83
82
|
getTransformFunctionWrapper() {
|
|
84
83
|
return `\n\npost(db, skInternalRequest, skInternalResponse).catch((err)=>{reject(err);});`;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VmEmptyResponseError = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const application_error_1 = tslib_1.__importDefault(require("../../error-handling/error/application-error"));
|
|
6
|
+
class VmEmptyResponseError extends application_error_1.default {
|
|
7
|
+
code = "VM_EMPTY_RESPONSE_ERROR";
|
|
8
|
+
suggestions = [
|
|
9
|
+
"You may forgot to return html somewhere, check config_documentHandler!",
|
|
10
|
+
];
|
|
11
|
+
}
|
|
12
|
+
exports.VmEmptyResponseError = VmEmptyResponseError;
|
|
@@ -4,10 +4,14 @@ export declare class AssetApiClient {
|
|
|
4
4
|
private sortParameters;
|
|
5
5
|
private agent;
|
|
6
6
|
private rateLimit;
|
|
7
|
+
private lowestRateLimit;
|
|
8
|
+
private isRetry;
|
|
7
9
|
constructor(authenticationToken: string, app: string, sortParameters: boolean);
|
|
8
10
|
fetchURL(url: string, variation: string): Promise<Response>;
|
|
11
|
+
setIsRetry(): void;
|
|
9
12
|
getRateLimit(): number;
|
|
10
13
|
reduceMaxRequestsPerSecond(): void;
|
|
14
|
+
increaseMaxRequestsPerSecond(): void;
|
|
11
15
|
private isValidUrl;
|
|
12
16
|
private setRateLimit;
|
|
13
17
|
}
|
|
@@ -16,7 +16,9 @@ class AssetApiClient {
|
|
|
16
16
|
keepAlive: true,
|
|
17
17
|
rejectUnauthorized: false,
|
|
18
18
|
});
|
|
19
|
-
rateLimit = __1.
|
|
19
|
+
rateLimit = __1.DEFAULT_REQUESTS_PER_SECOND;
|
|
20
|
+
lowestRateLimit = __1.DEFAULT_REQUESTS_PER_SECOND;
|
|
21
|
+
isRetry = false;
|
|
20
22
|
constructor(authenticationToken, app, sortParameters) {
|
|
21
23
|
this.authenticationToken = authenticationToken;
|
|
22
24
|
this.app = app;
|
|
@@ -39,11 +41,23 @@ class AssetApiClient {
|
|
|
39
41
|
method: "HEAD",
|
|
40
42
|
});
|
|
41
43
|
}
|
|
44
|
+
setIsRetry() {
|
|
45
|
+
this.isRetry = true;
|
|
46
|
+
this.rateLimit = this.lowestRateLimit;
|
|
47
|
+
}
|
|
42
48
|
getRateLimit() {
|
|
43
49
|
return this.rateLimit;
|
|
44
50
|
}
|
|
45
51
|
reduceMaxRequestsPerSecond() {
|
|
46
52
|
this.setRateLimit(this.rateLimit * __1.RATE_LIMIT_MULTIPLICATOR);
|
|
53
|
+
if (this.rateLimit < this.lowestRateLimit) {
|
|
54
|
+
this.lowestRateLimit = this.rateLimit;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
increaseMaxRequestsPerSecond() {
|
|
58
|
+
if (this.rateLimit + 1 <= __1.MAX_REQUESTS_PER_SECOND && !this.isRetry) {
|
|
59
|
+
this.setRateLimit(this.rateLimit + 1);
|
|
60
|
+
}
|
|
47
61
|
}
|
|
48
62
|
isValidUrl(url) {
|
|
49
63
|
if (!node_url_1.URL.canParse(url)) {
|
|
@@ -28,7 +28,8 @@ export declare enum ItemStatus {
|
|
|
28
28
|
export declare const MIN_TIME_TO_FETCH_BATCH = 1000;
|
|
29
29
|
export declare const FETCH_TIMEOUT = 10000;
|
|
30
30
|
export declare const TIMOUT_AFTER_DETECTED_RATE_LIMIT = 5000;
|
|
31
|
-
export declare const
|
|
31
|
+
export declare const DEFAULT_REQUESTS_PER_SECOND = 10;
|
|
32
|
+
export declare const MAX_REQUESTS_PER_SECOND = 20;
|
|
32
33
|
export declare const RATE_LIMIT_MULTIPLICATOR = 0.8;
|
|
33
34
|
export declare const RATE_LIMIT_CODES: string[];
|
|
34
35
|
export declare const TIMING_HEADER_ERROR_CODE_SELECTOR: RegExp;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DEFAULT_VARIATION = exports.VARIATION_SEPARATOR = exports.PROGRESS_BAR_FORMAT = exports.TIMING_HEADER_KEY = exports.TIMING_HEADER_ERROR_CODE_SELECTOR = exports.RATE_LIMIT_CODES = exports.RATE_LIMIT_MULTIPLICATOR = exports.
|
|
3
|
+
exports.DEFAULT_VARIATION = exports.VARIATION_SEPARATOR = exports.PROGRESS_BAR_FORMAT = exports.TIMING_HEADER_KEY = exports.TIMING_HEADER_ERROR_CODE_SELECTOR = exports.RATE_LIMIT_CODES = exports.RATE_LIMIT_MULTIPLICATOR = exports.MAX_REQUESTS_PER_SECOND = exports.DEFAULT_REQUESTS_PER_SECOND = exports.TIMOUT_AFTER_DETECTED_RATE_LIMIT = exports.FETCH_TIMEOUT = exports.MIN_TIME_TO_FETCH_BATCH = exports.ItemStatus = exports.PreWarmContext = void 0;
|
|
4
4
|
class PreWarmContext {
|
|
5
5
|
app;
|
|
6
6
|
path;
|
|
@@ -28,7 +28,8 @@ var ItemStatus;
|
|
|
28
28
|
exports.MIN_TIME_TO_FETCH_BATCH = 1000;
|
|
29
29
|
exports.FETCH_TIMEOUT = 10_000;
|
|
30
30
|
exports.TIMOUT_AFTER_DETECTED_RATE_LIMIT = 5000;
|
|
31
|
-
exports.
|
|
31
|
+
exports.DEFAULT_REQUESTS_PER_SECOND = 10;
|
|
32
|
+
exports.MAX_REQUESTS_PER_SECOND = 20;
|
|
32
33
|
exports.RATE_LIMIT_MULTIPLICATOR = 0.8;
|
|
33
34
|
exports.RATE_LIMIT_CODES = ["308", "310", "316"];
|
|
34
35
|
exports.TIMING_HEADER_ERROR_CODE_SELECTOR = /errorcode;desc=([^,]*),/;
|
|
@@ -63,6 +63,7 @@ class PreWarmService {
|
|
|
63
63
|
.getByStatus(_1.ItemStatus.RETRY)
|
|
64
64
|
.map((entry) => entry.url);
|
|
65
65
|
const retryList = this.generateAssetRequestList(urlsToRetry);
|
|
66
|
+
this.assetClient.setIsRetry();
|
|
66
67
|
await this.fetchUrls(retryList);
|
|
67
68
|
await this.printSummary(retryList);
|
|
68
69
|
}
|
|
@@ -152,7 +153,9 @@ class PreWarmService {
|
|
|
152
153
|
if (retryCount > 0) {
|
|
153
154
|
await this.sleep(_1.TIMOUT_AFTER_DETECTED_RATE_LIMIT);
|
|
154
155
|
this.assetClient.reduceMaxRequestsPerSecond();
|
|
156
|
+
return;
|
|
155
157
|
}
|
|
158
|
+
this.assetClient.increaseMaxRequestsPerSecond();
|
|
156
159
|
}
|
|
157
160
|
showMinimalStatusUpdate(batch, assetList) {
|
|
158
161
|
if (!this.cli.quiet) {
|
package/oclif.manifest.json
CHANGED