@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,624 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AutoscaledPool = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const timeout_1 = require("@apify/timeout");
6
+ const utilities_1 = require("@apify/utilities");
7
+ const ow_1 = tslib_1.__importDefault(require("ow"));
8
+ const configuration_1 = require("../configuration");
9
+ const log_1 = require("../log");
10
+ const snapshotter_1 = require("./snapshotter");
11
+ const system_status_1 = require("./system_status");
12
+ /**
13
+ * Manages a pool of asynchronous resource-intensive tasks that are executed in parallel.
14
+ * The pool only starts new tasks if there is enough free CPU and memory available
15
+ * and the Javascript event loop is not blocked.
16
+ *
17
+ * The information about the CPU and memory usage is obtained by the {@link Snapshotter} class,
18
+ * which makes regular snapshots of system resources that may be either local
19
+ * or from the Apify cloud infrastructure in case the process is running on the Apify platform.
20
+ * Meaningful data gathered from these snapshots is provided to `AutoscaledPool` by the {@link SystemStatus} class.
21
+ *
22
+ * Before running the pool, you need to implement the following three functions:
23
+ * {@link AutoscaledPoolOptions.runTaskFunction},
24
+ * {@link AutoscaledPoolOptions.isTaskReadyFunction} and
25
+ * {@link AutoscaledPoolOptions.isFinishedFunction}.
26
+ *
27
+ * The auto-scaled pool is started by calling the {@link AutoscaledPool.run} function.
28
+ * The pool periodically queries the {@link AutoscaledPoolOptions.isTaskReadyFunction} function
29
+ * for more tasks, managing optimal concurrency, until the function resolves to `false`. The pool then queries
30
+ * the {@link AutoscaledPoolOptions.isFinishedFunction}. If it resolves to `true`, the run finishes after all running tasks complete.
31
+ * If it resolves to `false`, it assumes there will be more tasks available later and keeps periodically querying for tasks.
32
+ * If any of the tasks throws then the {@link AutoscaledPool.run} function rejects the promise with an error.
33
+ *
34
+ * The pool evaluates whether it should start a new task every time one of the tasks finishes
35
+ * and also in the interval set by the `options.maybeRunIntervalSecs` parameter.
36
+ *
37
+ * **Example usage:**
38
+ *
39
+ * ```javascript
40
+ * const pool = new AutoscaledPool({
41
+ * maxConcurrency: 50,
42
+ * runTaskFunction: async () => {
43
+ * // Run some resource-intensive asynchronous operation here.
44
+ * },
45
+ * isTaskReadyFunction: async () => {
46
+ * // Tell the pool whether more tasks are ready to be processed.
47
+ * // Return true or false
48
+ * },
49
+ * isFinishedFunction: async () => {
50
+ * // Tell the pool whether it should finish
51
+ * // or wait for more tasks to become available.
52
+ * // Return true or false
53
+ * }
54
+ * });
55
+ *
56
+ * await pool.run();
57
+ * ```
58
+ * @category Scaling
59
+ */
60
+ class AutoscaledPool {
61
+ constructor(options, config = configuration_1.Configuration.getGlobalConfig()) {
62
+ Object.defineProperty(this, "config", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: config
67
+ });
68
+ Object.defineProperty(this, "log", {
69
+ enumerable: true,
70
+ configurable: true,
71
+ writable: true,
72
+ value: void 0
73
+ });
74
+ // Configurable properties.
75
+ Object.defineProperty(this, "desiredConcurrencyRatio", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: void 0
80
+ });
81
+ Object.defineProperty(this, "scaleUpStepRatio", {
82
+ enumerable: true,
83
+ configurable: true,
84
+ writable: true,
85
+ value: void 0
86
+ });
87
+ Object.defineProperty(this, "scaleDownStepRatio", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: void 0
92
+ });
93
+ Object.defineProperty(this, "maybeRunIntervalMillis", {
94
+ enumerable: true,
95
+ configurable: true,
96
+ writable: true,
97
+ value: void 0
98
+ });
99
+ Object.defineProperty(this, "loggingIntervalMillis", {
100
+ enumerable: true,
101
+ configurable: true,
102
+ writable: true,
103
+ value: void 0
104
+ });
105
+ Object.defineProperty(this, "autoscaleIntervalMillis", {
106
+ enumerable: true,
107
+ configurable: true,
108
+ writable: true,
109
+ value: void 0
110
+ });
111
+ Object.defineProperty(this, "taskTimeoutMillis", {
112
+ enumerable: true,
113
+ configurable: true,
114
+ writable: true,
115
+ value: void 0
116
+ });
117
+ Object.defineProperty(this, "runTaskFunction", {
118
+ enumerable: true,
119
+ configurable: true,
120
+ writable: true,
121
+ value: void 0
122
+ });
123
+ Object.defineProperty(this, "isFinishedFunction", {
124
+ enumerable: true,
125
+ configurable: true,
126
+ writable: true,
127
+ value: void 0
128
+ });
129
+ Object.defineProperty(this, "isTaskReadyFunction", {
130
+ enumerable: true,
131
+ configurable: true,
132
+ writable: true,
133
+ value: void 0
134
+ });
135
+ // Internal properties.
136
+ Object.defineProperty(this, "_minConcurrency", {
137
+ enumerable: true,
138
+ configurable: true,
139
+ writable: true,
140
+ value: void 0
141
+ });
142
+ Object.defineProperty(this, "_maxConcurrency", {
143
+ enumerable: true,
144
+ configurable: true,
145
+ writable: true,
146
+ value: void 0
147
+ });
148
+ Object.defineProperty(this, "_desiredConcurrency", {
149
+ enumerable: true,
150
+ configurable: true,
151
+ writable: true,
152
+ value: void 0
153
+ });
154
+ Object.defineProperty(this, "_currentConcurrency", {
155
+ enumerable: true,
156
+ configurable: true,
157
+ writable: true,
158
+ value: 0
159
+ });
160
+ Object.defineProperty(this, "isStopped", {
161
+ enumerable: true,
162
+ configurable: true,
163
+ writable: true,
164
+ value: false
165
+ });
166
+ Object.defineProperty(this, "lastLoggingTime", {
167
+ enumerable: true,
168
+ configurable: true,
169
+ writable: true,
170
+ value: 0
171
+ });
172
+ Object.defineProperty(this, "resolve", {
173
+ enumerable: true,
174
+ configurable: true,
175
+ writable: true,
176
+ value: null
177
+ });
178
+ Object.defineProperty(this, "reject", {
179
+ enumerable: true,
180
+ configurable: true,
181
+ writable: true,
182
+ value: null
183
+ });
184
+ Object.defineProperty(this, "snapshotter", {
185
+ enumerable: true,
186
+ configurable: true,
187
+ writable: true,
188
+ value: void 0
189
+ });
190
+ Object.defineProperty(this, "systemStatus", {
191
+ enumerable: true,
192
+ configurable: true,
193
+ writable: true,
194
+ value: void 0
195
+ });
196
+ Object.defineProperty(this, "poolPromise", {
197
+ enumerable: true,
198
+ configurable: true,
199
+ writable: true,
200
+ value: void 0
201
+ });
202
+ Object.defineProperty(this, "autoscaleInterval", {
203
+ enumerable: true,
204
+ configurable: true,
205
+ writable: true,
206
+ value: void 0
207
+ });
208
+ Object.defineProperty(this, "maybeRunInterval", {
209
+ enumerable: true,
210
+ configurable: true,
211
+ writable: true,
212
+ value: void 0
213
+ });
214
+ Object.defineProperty(this, "queryingIsTaskReady", {
215
+ enumerable: true,
216
+ configurable: true,
217
+ writable: true,
218
+ value: void 0
219
+ });
220
+ Object.defineProperty(this, "queryingIsFinished", {
221
+ enumerable: true,
222
+ configurable: true,
223
+ writable: true,
224
+ value: void 0
225
+ });
226
+ (0, ow_1.default)(options, ow_1.default.object.exactShape({
227
+ runTaskFunction: ow_1.default.function,
228
+ isFinishedFunction: ow_1.default.function,
229
+ isTaskReadyFunction: ow_1.default.function,
230
+ maxConcurrency: ow_1.default.optional.number,
231
+ minConcurrency: ow_1.default.optional.number,
232
+ desiredConcurrency: ow_1.default.optional.number,
233
+ desiredConcurrencyRatio: ow_1.default.optional.number,
234
+ scaleUpStepRatio: ow_1.default.optional.number,
235
+ scaleDownStepRatio: ow_1.default.optional.number,
236
+ maybeRunIntervalSecs: ow_1.default.optional.number,
237
+ loggingIntervalSecs: ow_1.default.any(ow_1.default.number, ow_1.default.nullOrUndefined),
238
+ autoscaleIntervalSecs: ow_1.default.optional.number,
239
+ taskTimeoutSecs: ow_1.default.optional.number,
240
+ systemStatusOptions: ow_1.default.optional.object,
241
+ snapshotterOptions: ow_1.default.optional.object,
242
+ log: ow_1.default.optional.object,
243
+ }));
244
+ const { runTaskFunction, isFinishedFunction, isTaskReadyFunction, maxConcurrency = 1000, minConcurrency = 1, desiredConcurrency, desiredConcurrencyRatio = 0.90, scaleUpStepRatio = 0.05, scaleDownStepRatio = 0.05, maybeRunIntervalSecs = 0.5, loggingIntervalSecs = 60, taskTimeoutSecs = 0, autoscaleIntervalSecs = 10, systemStatusOptions, snapshotterOptions, log = log_1.log, } = options;
245
+ this.log = log.child({ prefix: 'AutoscaledPool' });
246
+ // Configurable properties.
247
+ this.desiredConcurrencyRatio = desiredConcurrencyRatio;
248
+ this.scaleUpStepRatio = scaleUpStepRatio;
249
+ this.scaleDownStepRatio = scaleDownStepRatio;
250
+ this.maybeRunIntervalMillis = maybeRunIntervalSecs * 1000;
251
+ this.loggingIntervalMillis = loggingIntervalSecs * 1000;
252
+ this.autoscaleIntervalMillis = autoscaleIntervalSecs * 1000;
253
+ this.taskTimeoutMillis = taskTimeoutSecs * 1000;
254
+ this.runTaskFunction = runTaskFunction;
255
+ this.isFinishedFunction = isFinishedFunction;
256
+ this.isTaskReadyFunction = isTaskReadyFunction;
257
+ // Internal properties.
258
+ this._minConcurrency = minConcurrency;
259
+ this._maxConcurrency = maxConcurrency;
260
+ this._desiredConcurrency = desiredConcurrency ?? minConcurrency;
261
+ this._currentConcurrency = 0;
262
+ this.isStopped = false;
263
+ this.lastLoggingTime = 0;
264
+ this.resolve = null;
265
+ this.reject = null;
266
+ this._autoscale = this._autoscale.bind(this);
267
+ this._maybeRunTask = this._maybeRunTask.bind(this);
268
+ // Create instances with correct options.
269
+ const ssoCopy = { ...systemStatusOptions };
270
+ ssoCopy.snapshotter ?? (ssoCopy.snapshotter = new snapshotter_1.Snapshotter({
271
+ ...snapshotterOptions,
272
+ log: this.log,
273
+ config: this.config,
274
+ client: this.config.getStorageClient(),
275
+ }));
276
+ ssoCopy.config ?? (ssoCopy.config = this.config);
277
+ this.snapshotter = ssoCopy.snapshotter;
278
+ this.systemStatus = new system_status_1.SystemStatus(ssoCopy);
279
+ }
280
+ /**
281
+ * Gets the minimum number of tasks running in parallel.
282
+ */
283
+ get minConcurrency() {
284
+ return this._minConcurrency;
285
+ }
286
+ /**
287
+ * Sets the minimum number of tasks running in parallel.
288
+ *
289
+ * *WARNING:* If you set this value too high with respect to the available system memory and CPU, your code might run extremely slow or crash.
290
+ * If you're not sure, just keep the default value and the concurrency will scale up automatically.
291
+ */
292
+ set minConcurrency(value) {
293
+ (0, ow_1.default)(value, ow_1.default.number);
294
+ this._minConcurrency = value;
295
+ }
296
+ /**
297
+ * Gets the maximum number of tasks running in parallel.
298
+ */
299
+ get maxConcurrency() {
300
+ return this._maxConcurrency;
301
+ }
302
+ /**
303
+ * Sets the maximum number of tasks running in parallel.
304
+ */
305
+ set maxConcurrency(value) {
306
+ (0, ow_1.default)(value, ow_1.default.number);
307
+ this._maxConcurrency = value;
308
+ }
309
+ /**
310
+ * Gets the desired concurrency for the pool,
311
+ * which is an estimated number of parallel tasks that the system can currently support.
312
+ */
313
+ get desiredConcurrency() {
314
+ return this._desiredConcurrency;
315
+ }
316
+ /**
317
+ * Sets the desired concurrency for the pool, i.e. the number of tasks that should be running
318
+ * in parallel if there's large enough supply of tasks.
319
+ */
320
+ set desiredConcurrency(value) {
321
+ (0, ow_1.default)(value, ow_1.default.number);
322
+ this._desiredConcurrency = value;
323
+ }
324
+ /**
325
+ * Gets the the number of parallel tasks currently running in the pool.
326
+ */
327
+ get currentConcurrency() {
328
+ return this._currentConcurrency;
329
+ }
330
+ /**
331
+ * Runs the auto-scaled pool. Returns a promise that gets resolved or rejected once
332
+ * all the tasks are finished or one of them fails.
333
+ */
334
+ async run() {
335
+ this.poolPromise = new Promise((resolve, reject) => {
336
+ this.resolve = resolve;
337
+ this.reject = reject;
338
+ });
339
+ await this.snapshotter.start();
340
+ // This interval checks the system status and updates the desired concurrency accordingly.
341
+ this.autoscaleInterval = (0, utilities_1.betterSetInterval)(this._autoscale, this.autoscaleIntervalMillis);
342
+ // This is here because if we scale down to let's say 1, then after each promise is finished
343
+ // this._maybeRunTask() doesn't trigger another one. So if that 1 instance gets stuck it results
344
+ // in the actor getting stuck and even after scaling up it never triggers another promise.
345
+ this.maybeRunInterval = (0, utilities_1.betterSetInterval)(this._maybeRunTask, this.maybeRunIntervalMillis);
346
+ try {
347
+ await this.poolPromise;
348
+ }
349
+ finally {
350
+ // If resolve is null, the pool is already destroyed.
351
+ if (this.resolve)
352
+ await this._destroy();
353
+ }
354
+ }
355
+ /**
356
+ * Aborts the run of the auto-scaled pool and destroys it. The promise returned from
357
+ * the {@link AutoscaledPool.run} function will immediately resolve, no more new tasks
358
+ * will be spawned and all running tasks will be left in their current state.
359
+ *
360
+ * Due to the nature of the tasks, auto-scaled pool cannot reliably guarantee abortion
361
+ * of all the running tasks, therefore, no abortion is attempted and some of the tasks
362
+ * may finish, while others may not. Essentially, auto-scaled pool doesn't care about
363
+ * their state after the invocation of `.abort()`, but that does not mean that some
364
+ * parts of their asynchronous chains of commands will not execute.
365
+ */
366
+ async abort() {
367
+ this.isStopped = true;
368
+ if (this.resolve) {
369
+ this.resolve();
370
+ await this._destroy();
371
+ }
372
+ }
373
+ /**
374
+ * Prevents the auto-scaled pool from starting new tasks, but allows the running ones to finish
375
+ * (unlike abort, which terminates them). Used together with {@link AutoscaledPool.resume}
376
+ *
377
+ * The function's promise will resolve once all running tasks have completed and the pool
378
+ * is effectively idle. If the `timeoutSecs` argument is provided, the promise will reject
379
+ * with a timeout error after the `timeoutSecs` seconds.
380
+ *
381
+ * The promise returned from the {@link AutoscaledPool.run} function will not resolve
382
+ * when `.pause()` is invoked (unlike abort, which resolves it).
383
+ */
384
+ async pause(timeoutSecs) {
385
+ if (this.isStopped)
386
+ return;
387
+ this.isStopped = true;
388
+ return new Promise((resolve, reject) => {
389
+ let timeout;
390
+ if (timeoutSecs) {
391
+ timeout = setTimeout(() => {
392
+ const err = new Error('The pool\'s running tasks did not finish'
393
+ + `in ${timeoutSecs} secs after pool.pause() invocation.`);
394
+ reject(err);
395
+ }, timeoutSecs);
396
+ }
397
+ const interval = setInterval(() => {
398
+ if (this._currentConcurrency <= 0) {
399
+ // Clean up timeout and interval to prevent process hanging.
400
+ if (timeout)
401
+ clearTimeout(timeout);
402
+ clearInterval(interval);
403
+ resolve();
404
+ }
405
+ }, this.maybeRunIntervalMillis);
406
+ });
407
+ }
408
+ /**
409
+ * Resumes the operation of the autoscaled-pool by allowing more tasks to be run.
410
+ * Used together with {@link AutoscaledPool.pause}
411
+ *
412
+ * Tasks will automatically start running again in `options.maybeRunIntervalSecs`.
413
+ */
414
+ resume() {
415
+ this.isStopped = false;
416
+ }
417
+ /**
418
+ * Starts a new task
419
+ * if the number of running tasks (current concurrency) is lower than desired concurrency
420
+ * and the system is not currently overloaded
421
+ * and this.isTaskReadyFunction() returns true.
422
+ *
423
+ * It doesn't allow multiple concurrent runs of this method.
424
+ */
425
+ async _maybeRunTask(intervalCallback) {
426
+ this.log.perf('Attempting to run a task.');
427
+ // Check if the function was invoked by the maybeRunInterval and use an empty function if not.
428
+ const done = intervalCallback || (() => { });
429
+ // Prevent starting a new task if:
430
+ // - the pool is paused or aborted
431
+ if (this.isStopped) {
432
+ this.log.perf('Task will not run. AutoscaledPool is stopped.');
433
+ return done();
434
+ }
435
+ // - we are already querying for a task.
436
+ if (this.queryingIsTaskReady) {
437
+ this.log.perf('Task will not run. Waiting for a ready task.');
438
+ return done();
439
+ }
440
+ // - we would exceed desired concurrency.
441
+ if (this._currentConcurrency >= this._desiredConcurrency) {
442
+ this.log.perf('Task will not run. Desired concurrency achieved.');
443
+ return done();
444
+ }
445
+ // - system is overloaded now and we are at or above minConcurrency
446
+ const currentStatus = this.systemStatus.getCurrentStatus();
447
+ const { isSystemIdle } = currentStatus;
448
+ if (!isSystemIdle && this._currentConcurrency >= this._minConcurrency) {
449
+ this.log.perf('Task will not be run. System is overloaded.', currentStatus);
450
+ return done();
451
+ }
452
+ // - a task is ready.
453
+ this.queryingIsTaskReady = true;
454
+ let isTaskReady;
455
+ try {
456
+ this.log.perf('Checking for ready tasks.');
457
+ isTaskReady = await this.isTaskReadyFunction();
458
+ }
459
+ catch (e) {
460
+ const err = e;
461
+ this.log.perf('Checking for ready tasks failed.');
462
+ // We might have already rejected this promise.
463
+ if (this.reject) {
464
+ // No need to log all concurrent errors.
465
+ this.log.exception(err, 'isTaskReadyFunction failed');
466
+ this.reject(err);
467
+ }
468
+ }
469
+ finally {
470
+ this.queryingIsTaskReady = false;
471
+ }
472
+ if (!isTaskReady) {
473
+ this.log.perf('Task will not run. No tasks are ready.');
474
+ done();
475
+ // No tasks could mean that we're finished with all tasks.
476
+ return this._maybeFinish();
477
+ }
478
+ try {
479
+ // Everything's fine. Run task.
480
+ this._currentConcurrency++;
481
+ // Try to run next task to build up concurrency,
482
+ // but defer it so it doesn't create a cycle.
483
+ setImmediate(this._maybeRunTask);
484
+ // We need to restart interval here, so that it doesn't get blocked by a stalled task.
485
+ done();
486
+ // Execute the current task.
487
+ this.log.perf('Running a task.');
488
+ if (this.taskTimeoutMillis > 0) {
489
+ await (0, timeout_1.addTimeoutToPromise)(() => this.runTaskFunction(), this.taskTimeoutMillis, `runTaskFunction timed out after ${this.taskTimeoutMillis / 1000} seconds.`);
490
+ }
491
+ else {
492
+ await this.runTaskFunction();
493
+ }
494
+ this.log.perf('Task finished.');
495
+ this._currentConcurrency--;
496
+ // Run task after the previous one finished.
497
+ setImmediate(this._maybeRunTask);
498
+ }
499
+ catch (e) {
500
+ const err = e;
501
+ this.log.perf('Running a task failed.');
502
+ // We might have already rejected this promise.
503
+ if (this.reject) {
504
+ // No need to log all concurrent errors.
505
+ this.log.exception(err, 'runTaskFunction failed.');
506
+ this.reject(err);
507
+ }
508
+ }
509
+ }
510
+ /**
511
+ * Gets called every autoScaleIntervalSecs and evaluates the current system status.
512
+ * If the system IS NOT overloaded and the settings allow it, it scales up.
513
+ * If the system IS overloaded and the settings allow it, it scales down.
514
+ */
515
+ _autoscale(intervalCallback) {
516
+ // Don't scale if paused.
517
+ if (this.isStopped)
518
+ return intervalCallback();
519
+ // Only scale up if:
520
+ // - system has not been overloaded lately.
521
+ const systemStatus = this.systemStatus.getHistoricalStatus();
522
+ const { isSystemIdle } = systemStatus;
523
+ // - we're not already at max concurrency.
524
+ const weAreNotAtMax = this._desiredConcurrency < this._maxConcurrency;
525
+ // - current concurrency reaches at least the given ratio of desired concurrency.
526
+ const minCurrentConcurrency = Math.floor(this._desiredConcurrency * this.desiredConcurrencyRatio);
527
+ const weAreReachingDesiredConcurrency = this._currentConcurrency >= minCurrentConcurrency;
528
+ if (isSystemIdle && weAreNotAtMax && weAreReachingDesiredConcurrency)
529
+ this._scaleUp(systemStatus);
530
+ // Always scale down if:
531
+ // - the system has been overloaded lately.
532
+ const isSystemOverloaded = !isSystemIdle;
533
+ // - we're over min concurrency.
534
+ const weAreNotAtMin = this._desiredConcurrency > this._minConcurrency;
535
+ if (isSystemOverloaded && weAreNotAtMin)
536
+ this._scaleDown(systemStatus);
537
+ // On periodic intervals, print comprehensive log information
538
+ if (this.loggingIntervalMillis > 0) {
539
+ const now = Date.now();
540
+ if (now > this.lastLoggingTime + this.loggingIntervalMillis) {
541
+ this.lastLoggingTime = now;
542
+ this.log.info('state', {
543
+ currentConcurrency: this._currentConcurrency,
544
+ desiredConcurrency: this._desiredConcurrency,
545
+ systemStatus,
546
+ });
547
+ }
548
+ }
549
+ // Start a new interval cycle.
550
+ intervalCallback();
551
+ }
552
+ /**
553
+ * Scales the pool up by increasing
554
+ * the desired concurrency by the scaleUpStepRatio.
555
+ *
556
+ * @param systemStatus for logging
557
+ */
558
+ _scaleUp(systemStatus) {
559
+ const step = Math.ceil(this._desiredConcurrency * this.scaleUpStepRatio);
560
+ this._desiredConcurrency = Math.min(this._maxConcurrency, this._desiredConcurrency + step);
561
+ this.log.debug('scaling up', {
562
+ oldConcurrency: this._desiredConcurrency - step,
563
+ newConcurrency: this._desiredConcurrency,
564
+ systemStatus,
565
+ });
566
+ }
567
+ /**
568
+ * Scales the pool down by decreasing
569
+ * the desired concurrency by the scaleDownStepRatio.
570
+ *
571
+ * @param systemStatus for logging
572
+ */
573
+ _scaleDown(systemStatus) {
574
+ const step = Math.ceil(this._desiredConcurrency * this.scaleDownStepRatio);
575
+ this._desiredConcurrency = Math.max(this._minConcurrency, this._desiredConcurrency - step);
576
+ this.log.debug('scaling down', {
577
+ oldConcurrency: this._desiredConcurrency + step,
578
+ newConcurrency: this._desiredConcurrency,
579
+ systemStatus,
580
+ });
581
+ }
582
+ /**
583
+ * If there are no running tasks and this.isFinishedFunction() returns true then closes
584
+ * the pool and resolves the pool's promise returned by the run() method.
585
+ *
586
+ * It doesn't allow multiple concurrent runs of this method.
587
+ */
588
+ async _maybeFinish() {
589
+ if (this.queryingIsFinished)
590
+ return;
591
+ if (this._currentConcurrency > 0)
592
+ return;
593
+ this.queryingIsFinished = true;
594
+ try {
595
+ const isFinished = await this.isFinishedFunction();
596
+ if (isFinished && this.resolve)
597
+ this.resolve();
598
+ }
599
+ catch (e) {
600
+ const err = e;
601
+ if (this.reject) {
602
+ // No need to log all concurrent errors.
603
+ this.log.exception(err, 'isFinishedFunction failed.');
604
+ this.reject(err);
605
+ }
606
+ }
607
+ finally {
608
+ this.queryingIsFinished = false;
609
+ }
610
+ }
611
+ /**
612
+ * Cleans up resources.
613
+ */
614
+ async _destroy() {
615
+ this.resolve = null;
616
+ this.reject = null;
617
+ (0, utilities_1.betterClearInterval)(this.autoscaleInterval);
618
+ (0, utilities_1.betterClearInterval)(this.maybeRunInterval);
619
+ if (this.snapshotter)
620
+ await this.snapshotter.stop();
621
+ }
622
+ }
623
+ exports.AutoscaledPool = AutoscaledPool;
624
+ //# sourceMappingURL=autoscaled_pool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"autoscaled_pool.js","sourceRoot":"","sources":["../../src/autoscaling/autoscaled_pool.ts"],"names":[],"mappings":";;;;AACA,4CAAqD;AACrD,gDAA4F;AAC5F,oDAAoB;AACpB,oDAAiD;AACjD,gCAA2C;AAC3C,+CAAgE;AAChE,mDAAgF;AAgHhF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAa,cAAc;IAgCvB,YACI,OAA8B,EACb,SAAS,6BAAa,CAAC,eAAe,EAAE;;;;;mBAAxC;;QAjCrB;;;;;WAA0B;QAE1B,2BAA2B;QAC3B;;;;;WAAiD;Q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J;AA7dD,wCA6dC"}
@@ -0,0 +1,4 @@
1
+ export * from './autoscaled_pool';
2
+ export * from './snapshotter';
3
+ export * from './system_status';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/autoscaling/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,eAAe,CAAC;AAC9B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ tslib_1.__exportStar(require("./autoscaled_pool"), exports);
5
+ tslib_1.__exportStar(require("./snapshotter"), exports);
6
+ tslib_1.__exportStar(require("./system_status"), exports);
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/autoscaling/index.ts"],"names":[],"mappings":";;;AAAA,4DAAkC;AAClC,wDAA8B;AAC9B,0DAAgC"}