@crawlee/core 3.0.0-alpha.2 → 3.0.0-alpha.3

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.
Files changed (162) hide show
  1. package/dist/LICENSE.md +201 -0
  2. package/{README.md → dist/README.md} +0 -0
  3. package/dist/autoscaling/autoscaled_pool.d.ts +286 -0
  4. package/dist/autoscaling/autoscaled_pool.d.ts.map +1 -0
  5. package/dist/autoscaling/autoscaled_pool.js +624 -0
  6. package/dist/autoscaling/autoscaled_pool.js.map +1 -0
  7. package/dist/autoscaling/index.d.ts +4 -0
  8. package/dist/autoscaling/index.d.ts.map +1 -0
  9. package/dist/autoscaling/index.js +7 -0
  10. package/dist/autoscaling/index.js.map +1 -0
  11. package/dist/autoscaling/snapshotter.d.ts +193 -0
  12. package/dist/autoscaling/snapshotter.d.ts.map +1 -0
  13. package/dist/autoscaling/snapshotter.js +377 -0
  14. package/dist/autoscaling/snapshotter.js.map +1 -0
  15. package/dist/autoscaling/system_status.d.ts +181 -0
  16. package/dist/autoscaling/system_status.d.ts.map +1 -0
  17. package/dist/autoscaling/system_status.js +194 -0
  18. package/dist/autoscaling/system_status.js.map +1 -0
  19. package/dist/cache_container.d.ts +18 -0
  20. package/dist/cache_container.d.ts.map +1 -0
  21. package/dist/cache_container.js +42 -0
  22. package/dist/cache_container.js.map +1 -0
  23. package/dist/configuration.d.ts +150 -0
  24. package/dist/configuration.d.ts.map +1 -0
  25. package/dist/configuration.js +284 -0
  26. package/dist/configuration.js.map +1 -0
  27. package/dist/constants.d.ts +3 -0
  28. package/dist/constants.d.ts.map +1 -0
  29. package/dist/constants.js +6 -0
  30. package/dist/constants.js.map +1 -0
  31. package/dist/crawlers/crawler_commons.d.ts +23 -0
  32. package/dist/crawlers/crawler_commons.d.ts.map +1 -0
  33. package/dist/crawlers/crawler_commons.js +3 -0
  34. package/dist/crawlers/crawler_commons.js.map +1 -0
  35. package/dist/crawlers/crawler_extension.d.ts +11 -0
  36. package/dist/crawlers/crawler_extension.d.ts.map +1 -0
  37. package/dist/crawlers/crawler_extension.js +30 -0
  38. package/dist/crawlers/crawler_extension.js.map +1 -0
  39. package/dist/crawlers/crawler_utils.d.ts +25 -0
  40. package/dist/crawlers/crawler_utils.d.ts.map +1 -0
  41. package/dist/crawlers/crawler_utils.js +72 -0
  42. package/dist/crawlers/crawler_utils.js.map +1 -0
  43. package/dist/crawlers/index.d.ts +5 -0
  44. package/dist/crawlers/index.d.ts.map +1 -0
  45. package/dist/crawlers/index.js +8 -0
  46. package/dist/crawlers/index.js.map +1 -0
  47. package/dist/crawlers/statistics.d.ts +147 -0
  48. package/dist/crawlers/statistics.d.ts.map +1 -0
  49. package/dist/crawlers/statistics.js +360 -0
  50. package/dist/crawlers/statistics.js.map +1 -0
  51. package/dist/enqueue_links/enqueue_links.d.ts +138 -0
  52. package/dist/enqueue_links/enqueue_links.d.ts.map +1 -0
  53. package/dist/enqueue_links/enqueue_links.js +123 -0
  54. package/dist/enqueue_links/enqueue_links.js.map +1 -0
  55. package/dist/enqueue_links/index.d.ts +3 -0
  56. package/dist/enqueue_links/index.d.ts.map +1 -0
  57. package/dist/enqueue_links/index.js +6 -0
  58. package/dist/enqueue_links/index.js.map +1 -0
  59. package/dist/enqueue_links/shared.d.ts +60 -0
  60. package/dist/enqueue_links/shared.d.ts.map +1 -0
  61. package/dist/enqueue_links/shared.js +148 -0
  62. package/dist/enqueue_links/shared.js.map +1 -0
  63. package/dist/errors.d.ts +8 -0
  64. package/dist/errors.d.ts.map +1 -0
  65. package/dist/errors.js +12 -0
  66. package/dist/errors.js.map +1 -0
  67. package/dist/events/event_manager.d.ts +41 -0
  68. package/dist/events/event_manager.d.ts.map +1 -0
  69. package/dist/events/event_manager.js +103 -0
  70. package/dist/events/event_manager.js.map +1 -0
  71. package/dist/events/index.d.ts +3 -0
  72. package/dist/events/index.d.ts.map +1 -0
  73. package/dist/events/index.js +6 -0
  74. package/dist/events/index.js.map +1 -0
  75. package/dist/events/local_event_manager.d.ts +32 -0
  76. package/dist/events/local_event_manager.d.ts.map +1 -0
  77. package/dist/events/local_event_manager.js +114 -0
  78. package/dist/events/local_event_manager.js.map +1 -0
  79. package/dist/index.d.ts +14 -0
  80. package/dist/index.d.ts.map +1 -0
  81. package/dist/index.js +17 -0
  82. package/dist/index.js.map +1 -0
  83. package/dist/index.mjs +63 -0
  84. package/dist/log.d.ts +3 -0
  85. package/dist/log.d.ts.map +1 -0
  86. package/dist/log.js +12 -0
  87. package/dist/log.js.map +1 -0
  88. package/dist/package.json +82 -0
  89. package/dist/proxy_configuration.d.ts +181 -0
  90. package/dist/proxy_configuration.d.ts.map +1 -0
  91. package/dist/proxy_configuration.js +209 -0
  92. package/dist/proxy_configuration.js.map +1 -0
  93. package/dist/request.d.ts +174 -0
  94. package/dist/request.d.ts.map +1 -0
  95. package/dist/request.js +270 -0
  96. package/dist/request.js.map +1 -0
  97. package/dist/serialization.d.ts +33 -0
  98. package/dist/serialization.d.ts.map +1 -0
  99. package/dist/serialization.js +146 -0
  100. package/dist/serialization.js.map +1 -0
  101. package/dist/session_pool/errors.d.ts +8 -0
  102. package/dist/session_pool/errors.d.ts.map +1 -0
  103. package/dist/session_pool/errors.js +20 -0
  104. package/dist/session_pool/errors.js.map +1 -0
  105. package/dist/session_pool/events.d.ts +3 -0
  106. package/dist/session_pool/events.d.ts.map +1 -0
  107. package/dist/session_pool/events.js +6 -0
  108. package/dist/session_pool/events.js.map +1 -0
  109. package/dist/session_pool/index.d.ts +6 -0
  110. package/dist/session_pool/index.d.ts.map +1 -0
  111. package/dist/session_pool/index.js +9 -0
  112. package/dist/session_pool/index.js.map +1 -0
  113. package/dist/session_pool/session.d.ts +212 -0
  114. package/dist/session_pool/session.d.ts.map +1 -0
  115. package/dist/session_pool/session.js +360 -0
  116. package/dist/session_pool/session.js.map +1 -0
  117. package/dist/session_pool/session_pool.d.ts +222 -0
  118. package/dist/session_pool/session_pool.d.ts.map +1 -0
  119. package/dist/session_pool/session_pool.js +389 -0
  120. package/dist/session_pool/session_pool.js.map +1 -0
  121. package/dist/session_pool/session_utils.d.ts +9 -0
  122. package/dist/session_pool/session_utils.d.ts.map +1 -0
  123. package/dist/session_pool/session_utils.js +19 -0
  124. package/dist/session_pool/session_utils.js.map +1 -0
  125. package/dist/storages/dataset.d.ts +358 -0
  126. package/dist/storages/dataset.d.ts.map +1 -0
  127. package/dist/storages/dataset.js +415 -0
  128. package/dist/storages/dataset.js.map +1 -0
  129. package/dist/storages/index.d.ts +7 -0
  130. package/dist/storages/index.d.ts.map +1 -0
  131. package/dist/storages/index.js +11 -0
  132. package/dist/storages/index.js.map +1 -0
  133. package/dist/storages/key_value_store.d.ts +242 -0
  134. package/dist/storages/key_value_store.d.ts.map +1 -0
  135. package/dist/storages/key_value_store.js +319 -0
  136. package/dist/storages/key_value_store.js.map +1 -0
  137. package/dist/storages/request_list.d.ts +461 -0
  138. package/dist/storages/request_list.d.ts.map +1 -0
  139. package/dist/storages/request_list.js +715 -0
  140. package/dist/storages/request_list.js.map +1 -0
  141. package/dist/storages/request_queue.d.ts +312 -0
  142. package/dist/storages/request_queue.d.ts.map +1 -0
  143. package/dist/storages/request_queue.js +708 -0
  144. package/dist/storages/request_queue.js.map +1 -0
  145. package/dist/storages/storage.d.ts +260 -0
  146. package/dist/storages/storage.d.ts.map +1 -0
  147. package/dist/storages/storage.js +3 -0
  148. package/dist/storages/storage.js.map +1 -0
  149. package/dist/storages/storage_manager.d.ts +40 -0
  150. package/dist/storages/storage_manager.d.ts.map +1 -0
  151. package/dist/storages/storage_manager.js +119 -0
  152. package/dist/storages/storage_manager.js.map +1 -0
  153. package/dist/tsconfig.build.tsbuildinfo +1 -0
  154. package/dist/typedefs.d.ts +12 -0
  155. package/dist/typedefs.d.ts.map +1 -0
  156. package/dist/typedefs.js +15 -0
  157. package/dist/typedefs.js.map +1 -0
  158. package/dist/validators.d.ts +21 -0
  159. package/dist/validators.d.ts.map +1 -0
  160. package/dist/validators.js +26 -0
  161. package/dist/validators.js.map +1 -0
  162. package/package.json +11 -10
@@ -0,0 +1,181 @@
1
+ import { Snapshotter } from './snapshotter';
2
+ import { Configuration } from '../configuration';
3
+ /**
4
+ * Represents the current status of the system.
5
+ */
6
+ export interface SystemInfo {
7
+ /** If true, system is being overloaded. */
8
+ isSystemIdle: boolean;
9
+ memInfo: ClientInfo;
10
+ eventLoopInfo: ClientInfo;
11
+ cpuInfo: ClientInfo;
12
+ clientInfo: ClientInfo;
13
+ memCurrentBytes?: number;
14
+ /**
15
+ * Platform only property
16
+ * @internal
17
+ */
18
+ cpuCurrentUsage?: number;
19
+ /**
20
+ * Platform only property
21
+ * @internal
22
+ */
23
+ isCpuOverloaded?: boolean;
24
+ /**
25
+ * Platform only property
26
+ * @internal
27
+ */
28
+ createdAt?: Date;
29
+ }
30
+ export interface SystemStatusOptions {
31
+ /**
32
+ * Defines max age of snapshots used in the {@link SystemStatus.getCurrentStatus} measurement.
33
+ * @default 5
34
+ */
35
+ currentHistorySecs?: number;
36
+ /**
37
+ * Sets the maximum ratio of overloaded snapshots in a memory sample.
38
+ * If the sample exceeds this ratio, the system will be overloaded.
39
+ * @default 0.2
40
+ */
41
+ maxMemoryOverloadedRatio?: number;
42
+ /**
43
+ * Sets the maximum ratio of overloaded snapshots in an event loop sample.
44
+ * If the sample exceeds this ratio, the system will be overloaded.
45
+ * @default 0.6
46
+ */
47
+ maxEventLoopOverloadedRatio?: number;
48
+ /**
49
+ * Sets the maximum ratio of overloaded snapshots in a CPU sample.
50
+ * If the sample exceeds this ratio, the system will be overloaded.
51
+ * @default 0.4
52
+ */
53
+ maxCpuOverloadedRatio?: number;
54
+ /**
55
+ * Sets the maximum ratio of overloaded snapshots in a Client sample.
56
+ * If the sample exceeds this ratio, the system will be overloaded.
57
+ * @default 0.3
58
+ */
59
+ maxClientOverloadedRatio?: number;
60
+ /**
61
+ * The `Snapshotter` instance to be queried for `SystemStatus`.
62
+ */
63
+ snapshotter?: Snapshotter;
64
+ /** @internal */
65
+ config?: Configuration;
66
+ }
67
+ export interface ClientInfo {
68
+ isOverloaded: boolean;
69
+ limitRatio: number;
70
+ actualRatio: number;
71
+ }
72
+ export interface FinalStatistics {
73
+ requestsFinished: number;
74
+ requestsFailed: number;
75
+ retryHistogram: number[];
76
+ requestAvgFailedDurationMillis: number;
77
+ requestAvgFinishedDurationMillis: number;
78
+ requestsFinishedPerMinute: number;
79
+ requestsFailedPerMinute: number;
80
+ requestTotalDurationMillis: number;
81
+ requestsTotal: number;
82
+ crawlerRuntimeMillis: number;
83
+ }
84
+ /**
85
+ * Provides a simple interface to reading system status from a {@link Snapshotter} instance.
86
+ * It only exposes two functions {@link SystemStatus.getCurrentStatus}
87
+ * and {@link SystemStatus.getHistoricalStatus}.
88
+ * The system status is calculated using a weighted average of overloaded
89
+ * messages in the snapshots, with the weights being the time intervals
90
+ * between the snapshots. Each resource is calculated separately
91
+ * and the system is overloaded whenever at least one resource is overloaded.
92
+ * The class is used by the {@link AutoscaledPool} class.
93
+ *
94
+ * {@link SystemStatus.getCurrentStatus}
95
+ * returns a boolean that represents the current status of the system.
96
+ * The length of the current timeframe in seconds is configurable
97
+ * by the `currentHistorySecs` option and represents the max age
98
+ * of snapshots to be considered for the calculation.
99
+ *
100
+ * {@link SystemStatus.getHistoricalStatus}
101
+ * returns a boolean that represents the long-term status
102
+ * of the system. It considers the full snapshot history available
103
+ * in the {@link Snapshotter} instance.
104
+ * @category Scaling
105
+ */
106
+ export declare class SystemStatus {
107
+ private readonly currentHistorySecs;
108
+ private readonly maxMemoryOverloadedRatio;
109
+ private readonly maxEventLoopOverloadedRatio;
110
+ private readonly maxCpuOverloadedRatio;
111
+ private readonly maxClientOverloadedRatio;
112
+ private readonly snapshotter;
113
+ constructor(options?: SystemStatusOptions);
114
+ /**
115
+ * Returns an {@link SystemInfo} object with the following structure:
116
+ *
117
+ * ```javascript
118
+ * {
119
+ * isSystemIdle: Boolean,
120
+ * memInfo: Object,
121
+ * eventLoopInfo: Object,
122
+ * cpuInfo: Object
123
+ * }
124
+ * ```
125
+ *
126
+ * Where the `isSystemIdle` property is set to `false` if the system
127
+ * has been overloaded in the last `options.currentHistorySecs` seconds,
128
+ * and `true` otherwise.
129
+ */
130
+ getCurrentStatus(): SystemInfo;
131
+ /**
132
+ * Returns an {@link SystemInfo} object with the following structure:
133
+ *
134
+ * ```javascript
135
+ * {
136
+ * isSystemIdle: Boolean,
137
+ * memInfo: Object,
138
+ * eventLoopInfo: Object,
139
+ * cpuInfo: Object
140
+ * }
141
+ * ```
142
+ *
143
+ * Where the `isSystemIdle` property is set to `false` if the system
144
+ * has been overloaded in the full history of the {@link Snapshotter}
145
+ * (which is configurable in the {@link Snapshotter}) and `true` otherwise.
146
+ */
147
+ getHistoricalStatus(): SystemInfo;
148
+ /**
149
+ * Returns a system status object.
150
+ */
151
+ protected _isSystemIdle(sampleDurationMillis?: number): SystemInfo;
152
+ /**
153
+ * Returns an object with an isOverloaded property set to true
154
+ * if the memory has been overloaded in the last sampleDurationMillis.
155
+ */
156
+ protected _isMemoryOverloaded(sampleDurationMillis?: number): ClientInfo;
157
+ /**
158
+ * Returns an object with an isOverloaded property set to true
159
+ * if the event loop has been overloaded in the last sampleDurationMillis.
160
+ */
161
+ protected _isEventLoopOverloaded(sampleDurationMillis?: number): ClientInfo;
162
+ /**
163
+ * Returns an object with an isOverloaded property set to true
164
+ * if the CPU has been overloaded in the last sampleDurationMillis.
165
+ */
166
+ protected _isCpuOverloaded(sampleDurationMillis?: number): ClientInfo;
167
+ /**
168
+ * Returns an object with an isOverloaded property set to true
169
+ * if the client has been overloaded in the last sampleDurationMillis.
170
+ */
171
+ protected _isClientOverloaded(sampleDurationMillis?: number): ClientInfo;
172
+ /**
173
+ * Returns an object with sample information and an isOverloaded property
174
+ * set to true if at least the ratio of snapshots in the sample are overloaded.
175
+ */
176
+ protected _isSampleOverloaded<T extends {
177
+ createdAt: Date;
178
+ isOverloaded: boolean;
179
+ }>(sample: T[], ratio: number): ClientInfo;
180
+ }
181
+ //# sourceMappingURL=system_status.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system_status.d.ts","sourceRoot":"","sources":["../../src/autoscaling/system_status.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,2CAA2C;IAC3C,YAAY,EAAE,OAAO,CAAC;IACtB,OAAO,EAAE,UAAU,CAAC;IACpB,aAAa,EAAE,UAAU,CAAC;IAC1B,OAAO,EAAE,UAAU,CAAC;IACpB,UAAU,EAAE,UAAU,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;OAGG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,SAAS,CAAC,EAAE,IAAI,CAAC;CACpB;AAED,MAAM,WAAW,mBAAmB;IAChC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAElC;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,MAAM,CAAC;IAErC;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAE/B;;;;OAIG;IACH,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAElC;;OAEG;IACH,WAAW,CAAC,EAAE,WAAW,CAAC;IAE1B,gBAAgB;IAChB,MAAM,CAAC,EAAE,aAAa,CAAC;CAC1B;AAED,MAAM,WAAW,UAAU;IACvB,YAAY,EAAE,OAAO,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,eAAe;IAC5B,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,MAAM,C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E,OAAO,CAAA;KAAE,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,UAAU;CAoB9H"}
@@ -0,0 +1,194 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SystemStatus = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const ow_1 = tslib_1.__importDefault(require("ow"));
6
+ const utils_1 = require("@crawlee/utils");
7
+ const snapshotter_1 = require("./snapshotter");
8
+ /**
9
+ * Provides a simple interface to reading system status from a {@link Snapshotter} instance.
10
+ * It only exposes two functions {@link SystemStatus.getCurrentStatus}
11
+ * and {@link SystemStatus.getHistoricalStatus}.
12
+ * The system status is calculated using a weighted average of overloaded
13
+ * messages in the snapshots, with the weights being the time intervals
14
+ * between the snapshots. Each resource is calculated separately
15
+ * and the system is overloaded whenever at least one resource is overloaded.
16
+ * The class is used by the {@link AutoscaledPool} class.
17
+ *
18
+ * {@link SystemStatus.getCurrentStatus}
19
+ * returns a boolean that represents the current status of the system.
20
+ * The length of the current timeframe in seconds is configurable
21
+ * by the `currentHistorySecs` option and represents the max age
22
+ * of snapshots to be considered for the calculation.
23
+ *
24
+ * {@link SystemStatus.getHistoricalStatus}
25
+ * returns a boolean that represents the long-term status
26
+ * of the system. It considers the full snapshot history available
27
+ * in the {@link Snapshotter} instance.
28
+ * @category Scaling
29
+ */
30
+ class SystemStatus {
31
+ constructor(options = {}) {
32
+ Object.defineProperty(this, "currentHistorySecs", {
33
+ enumerable: true,
34
+ configurable: true,
35
+ writable: true,
36
+ value: void 0
37
+ });
38
+ Object.defineProperty(this, "maxMemoryOverloadedRatio", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: void 0
43
+ });
44
+ Object.defineProperty(this, "maxEventLoopOverloadedRatio", {
45
+ enumerable: true,
46
+ configurable: true,
47
+ writable: true,
48
+ value: void 0
49
+ });
50
+ Object.defineProperty(this, "maxCpuOverloadedRatio", {
51
+ enumerable: true,
52
+ configurable: true,
53
+ writable: true,
54
+ value: void 0
55
+ });
56
+ Object.defineProperty(this, "maxClientOverloadedRatio", {
57
+ enumerable: true,
58
+ configurable: true,
59
+ writable: true,
60
+ value: void 0
61
+ });
62
+ Object.defineProperty(this, "snapshotter", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: void 0
67
+ });
68
+ (0, ow_1.default)(options, ow_1.default.object.exactShape({
69
+ currentHistorySecs: ow_1.default.optional.number,
70
+ maxMemoryOverloadedRatio: ow_1.default.optional.number,
71
+ maxEventLoopOverloadedRatio: ow_1.default.optional.number,
72
+ maxCpuOverloadedRatio: ow_1.default.optional.number,
73
+ maxClientOverloadedRatio: ow_1.default.optional.number,
74
+ snapshotter: ow_1.default.optional.object,
75
+ config: ow_1.default.optional.object,
76
+ }));
77
+ const { currentHistorySecs = 5, maxMemoryOverloadedRatio = 0.2, maxEventLoopOverloadedRatio = 0.6, maxCpuOverloadedRatio = 0.4, maxClientOverloadedRatio = 0.3, snapshotter, config, } = options;
78
+ this.currentHistorySecs = currentHistorySecs * 1000;
79
+ this.maxMemoryOverloadedRatio = maxMemoryOverloadedRatio;
80
+ this.maxEventLoopOverloadedRatio = maxEventLoopOverloadedRatio;
81
+ this.maxCpuOverloadedRatio = maxCpuOverloadedRatio;
82
+ this.maxClientOverloadedRatio = maxClientOverloadedRatio;
83
+ this.snapshotter = snapshotter || new snapshotter_1.Snapshotter({ config });
84
+ }
85
+ /**
86
+ * Returns an {@link SystemInfo} object with the following structure:
87
+ *
88
+ * ```javascript
89
+ * {
90
+ * isSystemIdle: Boolean,
91
+ * memInfo: Object,
92
+ * eventLoopInfo: Object,
93
+ * cpuInfo: Object
94
+ * }
95
+ * ```
96
+ *
97
+ * Where the `isSystemIdle` property is set to `false` if the system
98
+ * has been overloaded in the last `options.currentHistorySecs` seconds,
99
+ * and `true` otherwise.
100
+ */
101
+ getCurrentStatus() {
102
+ return this._isSystemIdle(this.currentHistorySecs);
103
+ }
104
+ /**
105
+ * Returns an {@link SystemInfo} object with the following structure:
106
+ *
107
+ * ```javascript
108
+ * {
109
+ * isSystemIdle: Boolean,
110
+ * memInfo: Object,
111
+ * eventLoopInfo: Object,
112
+ * cpuInfo: Object
113
+ * }
114
+ * ```
115
+ *
116
+ * Where the `isSystemIdle` property is set to `false` if the system
117
+ * has been overloaded in the full history of the {@link Snapshotter}
118
+ * (which is configurable in the {@link Snapshotter}) and `true` otherwise.
119
+ */
120
+ getHistoricalStatus() {
121
+ return this._isSystemIdle();
122
+ }
123
+ /**
124
+ * Returns a system status object.
125
+ */
126
+ _isSystemIdle(sampleDurationMillis) {
127
+ const memInfo = this._isMemoryOverloaded(sampleDurationMillis);
128
+ const eventLoopInfo = this._isEventLoopOverloaded(sampleDurationMillis);
129
+ const cpuInfo = this._isCpuOverloaded(sampleDurationMillis);
130
+ const clientInfo = this._isClientOverloaded(sampleDurationMillis);
131
+ return {
132
+ isSystemIdle: !memInfo.isOverloaded && !eventLoopInfo.isOverloaded && !cpuInfo.isOverloaded && !clientInfo.isOverloaded,
133
+ memInfo,
134
+ eventLoopInfo,
135
+ cpuInfo,
136
+ clientInfo,
137
+ };
138
+ }
139
+ /**
140
+ * Returns an object with an isOverloaded property set to true
141
+ * if the memory has been overloaded in the last sampleDurationMillis.
142
+ */
143
+ _isMemoryOverloaded(sampleDurationMillis) {
144
+ const sample = this.snapshotter.getMemorySample(sampleDurationMillis);
145
+ return this._isSampleOverloaded(sample, this.maxMemoryOverloadedRatio);
146
+ }
147
+ /**
148
+ * Returns an object with an isOverloaded property set to true
149
+ * if the event loop has been overloaded in the last sampleDurationMillis.
150
+ */
151
+ _isEventLoopOverloaded(sampleDurationMillis) {
152
+ const sample = this.snapshotter.getEventLoopSample(sampleDurationMillis);
153
+ return this._isSampleOverloaded(sample, this.maxEventLoopOverloadedRatio);
154
+ }
155
+ /**
156
+ * Returns an object with an isOverloaded property set to true
157
+ * if the CPU has been overloaded in the last sampleDurationMillis.
158
+ */
159
+ _isCpuOverloaded(sampleDurationMillis) {
160
+ const sample = this.snapshotter.getCpuSample(sampleDurationMillis);
161
+ return this._isSampleOverloaded(sample, this.maxCpuOverloadedRatio);
162
+ }
163
+ /**
164
+ * Returns an object with an isOverloaded property set to true
165
+ * if the client has been overloaded in the last sampleDurationMillis.
166
+ */
167
+ _isClientOverloaded(sampleDurationMillis) {
168
+ const sample = this.snapshotter.getClientSample(sampleDurationMillis);
169
+ return this._isSampleOverloaded(sample, this.maxClientOverloadedRatio);
170
+ }
171
+ /**
172
+ * Returns an object with sample information and an isOverloaded property
173
+ * set to true if at least the ratio of snapshots in the sample are overloaded.
174
+ */
175
+ _isSampleOverloaded(sample, ratio) {
176
+ const weights = [];
177
+ const values = [];
178
+ for (let i = 1; i < sample.length; i++) {
179
+ const previous = sample[i - 1];
180
+ const current = sample[i];
181
+ const weight = +current.createdAt - +previous.createdAt;
182
+ weights.push(weight || 1); // Prevent errors from 0ms long intervals (sync) between snapshots.
183
+ values.push(+current.isOverloaded);
184
+ }
185
+ const wAvg = (0, utils_1.weightedAvg)(values, weights);
186
+ return {
187
+ isOverloaded: wAvg > ratio,
188
+ limitRatio: ratio,
189
+ actualRatio: Math.round(wAvg * 1000) / 1000,
190
+ };
191
+ }
192
+ }
193
+ exports.SystemStatus = SystemStatus;
194
+ //# sourceMappingURL=system_status.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system_status.js","sourceRoot":"","sources":["../../src/autoscaling/system_status.ts"],"names":[],"mappings":";;;;AAAA,oDAAoB;AACpB,0CAA6C;AAC7C,+CAA4C;AA8F5C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,YAAY;IAQrB,YAAY,UAA+B,EAAE;QAP7C;;;;;WAA4C;QAC5C;;;;;WAAkD;QAClD;;;;;WAAqD;QACrD;;;;;WAA+C;QAC/C;;;;;WAAkD;QAClD;;;;;WAA0C;QAGtC,IAAA,YAAE,EAAC,OAAO,EAAE,YAAE,CAAC,MAAM,CAAC,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C,CAAC;QACtE,OAAO,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,IAAI,CAAC,wBAAwB,CAAC,CAAC;IAC3E,CAAC;IAED;;;OAGG;IACO,mBAAmB,CAAuD,MAAW,EAAE,KAAa;QAC1G,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,MAAM,MAAM,GAAa,EAAE,CAAC;QAE5B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YACpC,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;YAC/B,MAAM,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC1B,MAAM,MAAM,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,CAAC,QAAQ,CAAC,SAAS,CAAC;YACxD,OAAO,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,mEAAmE;YAC9F,MAAM,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;SACtC;QAED,MAAM,IAAI,GAAG,IAAA,mBAAW,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;QAE1C,OAAO;YACH,YAAY,EAAE,IAAI,GAAG,KAAK;YAC1B,UAAU,EAAE,KAAK;YACjB,WAAW,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAC,GAAG,IAAI;SAC9C,CAAC;IACN,CAAC;CACJ;AA1JD,oCA0JC"}
@@ -0,0 +1,18 @@
1
+ import { LruCache } from '@apify/datastructures';
2
+ /**
3
+ * Used to manage all globally created caches, such as request queue cache
4
+ * or dataset cache. Before creation of this class, those caches were
5
+ * created as module scoped globals - untouchable. This proved problematic
6
+ * especially in tests, where caches would prevent test separation.
7
+ * @ignore
8
+ */
9
+ export declare class CacheContainer {
10
+ caches: Map<string, LruCache<any>>;
11
+ openCache(name: string, maxSize: number): LruCache;
12
+ getCache(name: string): LruCache | undefined;
13
+ clearCache(name: string): void;
14
+ clearAllCaches(): void;
15
+ }
16
+ declare const _default: CacheContainer;
17
+ export default _default;
18
+ //# sourceMappingURL=cache_container.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache_container.d.ts","sourceRoot":"","sources":["../src/cache_container.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD;;;;;;GAMG;AACH,qBAAa,cAAc;IACvB,MAAM,6BAA+B;IAErC,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ;IASlD,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAI5C,UAAU,CAAC,IAAI,EAAE,MAAM;IAKvB,cAAc;CAGjB;;AAED,wBAAoC"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CacheContainer = void 0;
4
+ const datastructures_1 = require("@apify/datastructures");
5
+ /**
6
+ * Used to manage all globally created caches, such as request queue cache
7
+ * or dataset cache. Before creation of this class, those caches were
8
+ * created as module scoped globals - untouchable. This proved problematic
9
+ * especially in tests, where caches would prevent test separation.
10
+ * @ignore
11
+ */
12
+ class CacheContainer {
13
+ constructor() {
14
+ Object.defineProperty(this, "caches", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: new Map()
19
+ });
20
+ }
21
+ openCache(name, maxSize) {
22
+ let cache = this.caches.get(name);
23
+ if (!cache) {
24
+ cache = new datastructures_1.LruCache({ maxLength: maxSize });
25
+ this.caches.set(name, cache);
26
+ }
27
+ return cache;
28
+ }
29
+ getCache(name) {
30
+ return this.caches.get(name);
31
+ }
32
+ clearCache(name) {
33
+ const cache = this.caches.get(name);
34
+ cache?.clear();
35
+ }
36
+ clearAllCaches() {
37
+ this.caches.forEach((cache) => cache.clear());
38
+ }
39
+ }
40
+ exports.CacheContainer = CacheContainer;
41
+ exports.default = new CacheContainer();
42
+ //# sourceMappingURL=cache_container.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache_container.js","sourceRoot":"","sources":["../src/cache_container.ts"],"names":[],"mappings":";;;AAAA,0DAAiD;AAEjD;;;;;;GAMG;AACH,MAAa,cAAc;IAA3B;QACI;;;;mBAAS,IAAI,GAAG,EAAoB;WAAC;IAuBzC,CAAC;IArBG,SAAS,CAAC,IAAY,EAAE,OAAe;QACnC,IAAI,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,KAAK,EAAE;YACR,KAAK,GAAG,IAAI,yBAAQ,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CAAC;YAC7C,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;SAChC;QACD,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,QAAQ,CAAC,IAAY;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IAED,UAAU,CAAC,IAAY;QACnB,MAAM,KAAK,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACpC,KAAK,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC;IAED,cAAc;QACV,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAC;IAClD,CAAC;CACJ;AAxBD,wCAwBC;AAED,kBAAe,IAAI,cAAc,EAAE,CAAC"}
@@ -0,0 +1,150 @@
1
+ /// <reference types="node" />
2
+ import { ApifyStorageLocal, ApifyStorageLocalOptions } from '@apify/storage-local';
3
+ import { AsyncLocalStorage } from 'async_hooks';
4
+ import { Dictionary } from './typedefs';
5
+ import { StorageClient } from './storages/storage';
6
+ import { EventManager } from './events';
7
+ export interface ConfigurationOptions {
8
+ storageClient?: StorageClient;
9
+ eventManager?: EventManager;
10
+ storageClientOptions?: Dictionary;
11
+ defaultDatasetId?: string;
12
+ defaultKeyValueStoreId?: string;
13
+ defaultRequestQueueId?: string;
14
+ maxUsedCpuRatio?: number;
15
+ availableMemoryRatio?: number;
16
+ persistStateIntervalMillis?: number;
17
+ systemInfoIntervalMillis?: number;
18
+ metamorphAfterSleepMillis?: number;
19
+ inputKey?: string;
20
+ actorId?: string;
21
+ actorRunId?: string;
22
+ actorTaskId?: string;
23
+ containerPort?: number;
24
+ containerUrl?: string;
25
+ proxyHostname?: string;
26
+ proxyPassword?: string;
27
+ proxyPort?: number;
28
+ }
29
+ /**
30
+ * `Configuration` is a value object holding the SDK configuration. We can use it in two ways:
31
+ *
32
+ * 1. When using `Apify` class, we can get the instance configuration via `sdk.config`
33
+ * ```js
34
+ * const { Apify } = require('apify');
35
+ *
36
+ * const sdk = new Apify({ token: '123' });
37
+ * console.log(sdk.config.get('token')); // '123'
38
+ * ```
39
+ * 2. To get the global configuration (singleton instance). It will respect the environment variables.
40
+ * ```js
41
+ * // returns the token from APIFY_TOKEN env var
42
+ * console.log(Configuration.getGlobalConfig().get('token'));
43
+ * ```
44
+ *
45
+ * ## Supported Configuration Options
46
+ *
47
+ * Key | Environment Variable | Default Value
48
+ * ---|---|---
49
+ * `defaultDatasetId` | `APIFY_DEFAULT_DATASET_ID` | `'default'`
50
+ * `defaultKeyValueStoreId` | `APIFY_DEFAULT_KEY_VALUE_STORE_ID` | `'default'`
51
+ * `defaultRequestQueueId` | `APIFY_DEFAULT_REQUEST_QUEUE_ID` | `'default'`
52
+ * `persistStateIntervalMillis` | `APIFY_PERSIST_STATE_INTERVAL_MILLIS` | `60e3`
53
+ *
54
+ * ## Advanced Configuration Options
55
+ *
56
+ * Key | Environment Variable | Default Value
57
+ * ---|---|---
58
+ * `actorId` | `APIFY_ACTOR_ID` | -
59
+ * `actorRunId` | `APIFY_ACTOR_RUN_ID` | -
60
+ * `actorTaskId` | `APIFY_ACTOR_TASK_ID` | -
61
+ * `containerPort` | `APIFY_CONTAINER_PORT` | `4321`
62
+ * `containerUrl` | `APIFY_CONTAINER_URL` | `'http://localhost:4321'`
63
+ * `inputKey` | `APIFY_INPUT_KEY` | `'INPUT'`
64
+ * `metamorphAfterSleepMillis` | `APIFY_METAMORPH_AFTER_SLEEP_MILLIS` | `300e3`
65
+ * `proxyHostname` | `APIFY_PROXY_HOSTNAME` | `'proxy.apify.com'`
66
+ * `proxyPassword` | `APIFY_PROXY_PASSWORD` | -
67
+ * `proxyPort` | `APIFY_PROXY_PORT` | `8000`
68
+ *
69
+ * ## Not Supported environment variables
70
+ *
71
+ * - `MEMORY_MBYTES`
72
+ * - `HEADLESS`
73
+ * - `XVFB`
74
+ * - `CHROME_EXECUTABLE_PATH`
75
+ */
76
+ export declare class Configuration {
77
+ /**
78
+ * Maps environment variables to config keys (e.g. `APIFY_PROXY_PORT` to `proxyPort`)
79
+ */
80
+ private static ENV_MAP;
81
+ /**
82
+ * Maps config keys to environment variables (e.g. `proxyPort` to `APIFY_PROXY_PORT`).
83
+ */
84
+ private static ENV_MAP_REVERSED;
85
+ private static BOOLEAN_VARS;
86
+ private static INTEGER_VARS;
87
+ private static DEFAULTS;
88
+ /**
89
+ * Provides access to the current-instance-scoped Configuration without passing it around in parameters.
90
+ * @internal
91
+ */
92
+ static storage: AsyncLocalStorage<Configuration>;
93
+ private options;
94
+ private services;
95
+ private static globalConfig?;
96
+ /**
97
+ * Creates new `Configuration` instance with provided options. Env vars will have precedence over those.
98
+ */
99
+ constructor(options?: ConfigurationOptions);
100
+ /**
101
+ * Returns configured value. First checks the environment variables, then provided configuration,
102
+ * fallbacks to the `defaultValue` argument if provided, otherwise uses the default value as described
103
+ * in the above section.
104
+ */
105
+ get<T extends keyof ConfigurationOptions, U extends ConfigurationOptions[T]>(key: T, defaultValue?: U): U;
106
+ private _castEnvValue;
107
+ /**
108
+ * Sets value for given option. Only affects this `Configuration` instance, the value will not be propagated down to the env var.
109
+ * To reset a value, we can omit the `value` argument or pass `undefined` there.
110
+ */
111
+ set(key: keyof ConfigurationOptions, value?: any): void;
112
+ /**
113
+ * Returns cached instance of {@link StorageClient} using options as defined in the environment variables or in
114
+ * this {@link Configuration} instance. Only first call of this method will create the client, following calls will
115
+ * return the same client instance.
116
+ *
117
+ * Caching works based on the API URL and token, so calling this method with different options will return
118
+ * multiple instances, one for each variant of the options.
119
+ * @internal
120
+ */
121
+ getStorageClient(): StorageClient;
122
+ getEventManager(): EventManager;
123
+ /**
124
+ * Creates an instance of ApifyStorageLocal using options as defined in the environment variables or in this `Configuration` instance.
125
+ * @internal
126
+ */
127
+ createStorageLocal(options?: ApifyStorageLocalOptions): ApifyStorageLocal;
128
+ useStorageClient(client: StorageClient): void;
129
+ useEventManager(events: EventManager): void;
130
+ /**
131
+ * Returns the global configuration instance. It will respect the environment variables.
132
+ * When used inside SDK instance (`sdk.main()`), the return value is equal to `sdk.config`.
133
+ *
134
+ */
135
+ static getGlobalConfig(): Configuration;
136
+ /**
137
+ * Gets default {@link StorageClient} instance.
138
+ */
139
+ static getStorageClient(): StorageClient;
140
+ /**
141
+ * Gets default {@link EventManager} instance.
142
+ */
143
+ static getEventManager(): EventManager;
144
+ /**
145
+ * Resets global configuration instance. The default instance holds configuration based on env vars,
146
+ * if we want to change them, we need to first reset the global state. Used mainly for testing purposes.
147
+ */
148
+ static resetGlobalState(): void;
149
+ }
150
+ //# sourceMappingURL=configuration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configuration.d.ts","sourceRoot":"","sources":["../src/configuration.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,sBAAsB,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EAAE,UAAU,EAAW,MAAM,YAAY,CAAC;AACjD,OAAO,EAAE,aAAa,EAA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