@crawlee/core 4.0.0-beta.13 → 4.0.0-beta.130
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/README.md +17 -13
- package/autoscaling/autoscaled_pool.d.ts +67 -172
- package/autoscaling/autoscaled_pool.js +182 -329
- package/autoscaling/concurrency_system.d.ts +268 -0
- package/autoscaling/concurrency_system.js +362 -0
- package/autoscaling/cpu_load_signal.d.ts +43 -0
- package/autoscaling/cpu_load_signal.js +47 -0
- package/autoscaling/event_loop_load_signal.d.ts +51 -0
- package/autoscaling/event_loop_load_signal.js +60 -0
- package/autoscaling/index.d.ts +6 -1
- package/autoscaling/index.js +6 -1
- package/autoscaling/load_signal.d.ts +100 -0
- package/autoscaling/load_signal.js +105 -0
- package/autoscaling/memory_load_signal.d.ts +47 -0
- package/autoscaling/memory_load_signal.js +106 -0
- package/autoscaling/snapshotter.d.ts +58 -163
- package/autoscaling/snapshotter.js +45 -263
- package/autoscaling/storage_backend_load_signal.d.ts +56 -0
- package/autoscaling/storage_backend_load_signal.js +73 -0
- package/autoscaling/system_status.d.ts +67 -89
- package/autoscaling/system_status.js +92 -122
- package/autoscaling/weighted_avg.d.ts +5 -0
- package/autoscaling/weighted_avg.js +14 -0
- package/byte_utils.d.ts +17 -0
- package/byte_utils.js +42 -0
- package/configuration.d.ts +96 -223
- package/configuration.js +170 -222
- package/cookie_utils.d.ts +3 -2
- package/cookie_utils.js +18 -7
- package/crawlers/context_pipeline.d.ts +10 -1
- package/crawlers/context_pipeline.js +31 -8
- package/crawlers/crawler_commons.d.ts +90 -129
- package/crawlers/crawler_commons.js +1 -116
- package/crawlers/error_snapshotter.d.ts +2 -5
- package/crawlers/error_snapshotter.js +7 -8
- package/crawlers/error_tracker.d.ts +0 -1
- package/crawlers/error_tracker.js +0 -1
- package/crawlers/index.d.ts +1 -3
- package/crawlers/index.js +0 -3
- package/crawlers/internals/types.d.ts +0 -1
- package/crawlers/internals/types.js +0 -1
- package/crawlers/statistics.d.ts +187 -63
- package/crawlers/statistics.js +354 -164
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/enqueue_links/enqueue_links.d.ts +68 -154
- package/enqueue_links/enqueue_links.js +38 -210
- package/enqueue_links/index.d.ts +0 -1
- package/enqueue_links/index.js +0 -1
- package/enqueue_links/shared.d.ts +52 -26
- package/enqueue_links/shared.js +115 -66
- package/errors.d.ts +72 -4
- package/errors.js +89 -5
- package/events/event_manager.d.ts +35 -9
- package/events/event_manager.js +12 -13
- package/events/index.d.ts +0 -1
- package/events/index.js +0 -1
- package/events/local_event_manager.d.ts +15 -3
- package/events/local_event_manager.js +39 -13
- package/http.d.ts +9 -0
- package/http.js +28 -0
- package/index.d.ts +7 -4
- package/index.js +6 -3
- package/iterables.d.ts +79 -0
- package/iterables.js +134 -0
- package/log.d.ts +82 -3
- package/log.js +106 -1
- package/memory-storage/consts.d.ts +4 -0
- package/memory-storage/consts.js +4 -0
- package/memory-storage/index.d.ts +1 -0
- package/memory-storage/index.js +1 -0
- package/memory-storage/memory-storage.d.ts +38 -0
- package/memory-storage/memory-storage.js +130 -0
- package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
- package/memory-storage/resource-clients/common/base-client.js +6 -0
- package/memory-storage/resource-clients/dataset.d.ts +40 -0
- package/memory-storage/resource-clients/dataset.js +108 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
- package/memory-storage/resource-clients/key-value-store.js +201 -0
- package/memory-storage/resource-clients/request-queue.d.ts +77 -0
- package/memory-storage/resource-clients/request-queue.js +409 -0
- package/memory-storage/utils.d.ts +16 -0
- package/memory-storage/utils.js +41 -0
- package/owned_or_injected.d.ts +58 -0
- package/owned_or_injected.js +98 -0
- package/package.json +14 -13
- package/proxy_configuration.d.ts +24 -132
- package/proxy_configuration.js +32 -147
- package/recoverable_state.d.ts +155 -0
- package/recoverable_state.js +231 -0
- package/request.d.ts +80 -16
- package/request.js +147 -68
- package/router.d.ts +193 -21
- package/router.js +188 -43
- package/serialization.d.ts +0 -1
- package/serialization.js +15 -15
- package/service_locator.d.ts +165 -0
- package/service_locator.js +253 -0
- package/session_pool/consts.d.ts +1 -2
- package/session_pool/consts.js +1 -2
- package/session_pool/errors.d.ts +0 -1
- package/session_pool/errors.js +0 -1
- package/session_pool/fingerprint.d.ts +9 -0
- package/session_pool/fingerprint.js +30 -0
- package/session_pool/index.d.ts +0 -2
- package/session_pool/index.js +0 -2
- package/session_pool/session.d.ts +35 -88
- package/session_pool/session.js +101 -159
- package/session_pool/session_pool.d.ts +73 -91
- package/session_pool/session_pool.js +172 -165
- package/storages/batched_adds.d.ts +37 -0
- package/storages/batched_adds.js +73 -0
- package/storages/dataset.d.ts +114 -54
- package/storages/dataset.js +291 -148
- package/storages/index.d.ts +10 -8
- package/storages/index.js +8 -8
- package/storages/key_value_store.d.ts +185 -42
- package/storages/key_value_store.js +445 -169
- package/storages/key_value_store_codec.d.ts +32 -0
- package/storages/key_value_store_codec.js +113 -0
- package/storages/request_dedup_cache.d.ts +22 -0
- package/storages/request_dedup_cache.js +48 -0
- package/storages/request_list.d.ts +52 -115
- package/storages/request_list.js +183 -152
- package/storages/request_loader.d.ts +101 -0
- package/storages/request_loader.js +1 -0
- package/storages/request_manager.d.ts +33 -0
- package/storages/request_manager.js +1 -0
- package/storages/request_manager_tandem.d.ts +97 -0
- package/storages/request_manager_tandem.js +197 -0
- package/storages/request_queue.d.ts +290 -47
- package/storages/request_queue.js +762 -216
- package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +45 -89
- package/storages/sitemap_request_loader.js +438 -0
- package/storages/storage_instance_manager.d.ts +87 -0
- package/storages/storage_instance_manager.js +256 -0
- package/storages/storage_stats.d.ts +48 -0
- package/storages/storage_stats.js +29 -0
- package/storages/throttling_request_manager.d.ts +239 -0
- package/storages/throttling_request_manager.js +646 -0
- package/storages/transaction.d.ts +252 -0
- package/storages/transaction.js +251 -0
- package/storages/utils.d.ts +59 -11
- package/storages/utils.js +75 -15
- package/system-info/cpu-info.d.ts +67 -0
- package/system-info/cpu-info.js +216 -0
- package/system-info/memory-info.d.ts +31 -0
- package/system-info/memory-info.js +115 -0
- package/system-info/ps-tree.d.ts +17 -0
- package/system-info/ps-tree.js +144 -0
- package/system-info/runtime.d.ts +14 -0
- package/system-info/runtime.js +80 -0
- package/typedefs.d.ts +0 -6
- package/typedefs.js +0 -1
- package/url.d.ts +9 -0
- package/url.js +11 -0
- package/validators.d.ts +22 -18
- package/validators.js +13 -18
- package/autoscaling/autoscaled_pool.d.ts.map +0 -1
- package/autoscaling/autoscaled_pool.js.map +0 -1
- package/autoscaling/index.d.ts.map +0 -1
- package/autoscaling/index.js.map +0 -1
- package/autoscaling/snapshotter.d.ts.map +0 -1
- package/autoscaling/snapshotter.js.map +0 -1
- package/autoscaling/system_status.d.ts.map +0 -1
- package/autoscaling/system_status.js.map +0 -1
- package/configuration.d.ts.map +0 -1
- package/configuration.js.map +0 -1
- package/cookie_utils.d.ts.map +0 -1
- package/cookie_utils.js.map +0 -1
- package/crawlers/context_pipeline.d.ts.map +0 -1
- package/crawlers/context_pipeline.js.map +0 -1
- package/crawlers/crawler_commons.d.ts.map +0 -1
- package/crawlers/crawler_commons.js.map +0 -1
- package/crawlers/crawler_utils.d.ts +0 -10
- package/crawlers/crawler_utils.d.ts.map +0 -1
- package/crawlers/crawler_utils.js +0 -12
- package/crawlers/crawler_utils.js.map +0 -1
- package/crawlers/error_snapshotter.d.ts.map +0 -1
- package/crawlers/error_snapshotter.js.map +0 -1
- package/crawlers/error_tracker.d.ts.map +0 -1
- package/crawlers/error_tracker.js.map +0 -1
- package/crawlers/index.d.ts.map +0 -1
- package/crawlers/index.js.map +0 -1
- package/crawlers/internals/types.d.ts.map +0 -1
- package/crawlers/internals/types.js.map +0 -1
- package/crawlers/statistics.d.ts.map +0 -1
- package/crawlers/statistics.js.map +0 -1
- package/enqueue_links/enqueue_links.d.ts.map +0 -1
- package/enqueue_links/enqueue_links.js.map +0 -1
- package/enqueue_links/index.d.ts.map +0 -1
- package/enqueue_links/index.js.map +0 -1
- package/enqueue_links/shared.d.ts.map +0 -1
- package/enqueue_links/shared.js.map +0 -1
- package/errors.d.ts.map +0 -1
- package/errors.js.map +0 -1
- package/events/event_manager.d.ts.map +0 -1
- package/events/event_manager.js.map +0 -1
- package/events/index.d.ts.map +0 -1
- package/events/index.js.map +0 -1
- package/events/local_event_manager.d.ts.map +0 -1
- package/events/local_event_manager.js.map +0 -1
- package/http_clients/base-http-client.d.ts +0 -140
- package/http_clients/base-http-client.d.ts.map +0 -1
- package/http_clients/base-http-client.js +0 -40
- package/http_clients/base-http-client.js.map +0 -1
- package/http_clients/form-data-like.d.ts +0 -67
- package/http_clients/form-data-like.d.ts.map +0 -1
- package/http_clients/form-data-like.js +0 -5
- package/http_clients/form-data-like.js.map +0 -1
- package/http_clients/got-scraping-http-client.d.ts +0 -20
- package/http_clients/got-scraping-http-client.d.ts.map +0 -1
- package/http_clients/got-scraping-http-client.js +0 -82
- package/http_clients/got-scraping-http-client.js.map +0 -1
- package/http_clients/index.d.ts +0 -3
- package/http_clients/index.d.ts.map +0 -1
- package/http_clients/index.js +0 -3
- package/http_clients/index.js.map +0 -1
- package/index.d.ts.map +0 -1
- package/index.js.map +0 -1
- package/log.d.ts.map +0 -1
- package/log.js.map +0 -1
- package/proxy_configuration.d.ts.map +0 -1
- package/proxy_configuration.js.map +0 -1
- package/request.d.ts.map +0 -1
- package/request.js.map +0 -1
- package/router.d.ts.map +0 -1
- package/router.js.map +0 -1
- package/serialization.d.ts.map +0 -1
- package/serialization.js.map +0 -1
- package/session_pool/consts.d.ts.map +0 -1
- package/session_pool/consts.js.map +0 -1
- package/session_pool/errors.d.ts.map +0 -1
- package/session_pool/errors.js.map +0 -1
- package/session_pool/events.d.ts +0 -3
- package/session_pool/events.d.ts.map +0 -1
- package/session_pool/events.js +0 -3
- package/session_pool/events.js.map +0 -1
- package/session_pool/index.d.ts.map +0 -1
- package/session_pool/index.js.map +0 -1
- package/session_pool/session.d.ts.map +0 -1
- package/session_pool/session.js.map +0 -1
- package/session_pool/session_pool.d.ts.map +0 -1
- package/session_pool/session_pool.js.map +0 -1
- package/storages/access_checking.d.ts +0 -13
- package/storages/access_checking.d.ts.map +0 -1
- package/storages/access_checking.js +0 -14
- package/storages/access_checking.js.map +0 -1
- package/storages/dataset.d.ts.map +0 -1
- package/storages/dataset.js.map +0 -1
- package/storages/index.d.ts.map +0 -1
- package/storages/index.js.map +0 -1
- package/storages/key_value_store.d.ts.map +0 -1
- package/storages/key_value_store.js.map +0 -1
- package/storages/request_list.d.ts.map +0 -1
- package/storages/request_list.js.map +0 -1
- package/storages/request_provider.d.ts +0 -308
- package/storages/request_provider.d.ts.map +0 -1
- package/storages/request_provider.js +0 -555
- package/storages/request_provider.js.map +0 -1
- package/storages/request_queue.d.ts.map +0 -1
- package/storages/request_queue.js.map +0 -1
- package/storages/request_queue_v2.d.ts +0 -87
- package/storages/request_queue_v2.d.ts.map +0 -1
- package/storages/request_queue_v2.js +0 -438
- package/storages/request_queue_v2.js.map +0 -1
- package/storages/sitemap_request_list.d.ts.map +0 -1
- package/storages/sitemap_request_list.js +0 -430
- package/storages/sitemap_request_list.js.map +0 -1
- package/storages/storage_manager.d.ts +0 -58
- package/storages/storage_manager.d.ts.map +0 -1
- package/storages/storage_manager.js +0 -105
- package/storages/storage_manager.js.map +0 -1
- package/storages/utils.d.ts.map +0 -1
- package/storages/utils.js.map +0 -1
- package/tsconfig.build.tsbuildinfo +0 -1
- package/typedefs.d.ts.map +0 -1
- package/typedefs.js.map +0 -1
- package/validators.d.ts.map +0 -1
- package/validators.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
<h1 align="center">
|
|
2
2
|
<a href="https://crawlee.dev">
|
|
3
3
|
<picture>
|
|
4
|
-
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-dark.svg?sanitize=true"
|
|
5
|
-
<img alt="Crawlee" src="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-light.svg?sanitize=true" width="500"
|
|
4
|
+
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-dark.svg?sanitize=true" />
|
|
5
|
+
<img alt="Crawlee" src="https://raw.githubusercontent.com/apify/crawlee/master/website/static/img/crawlee-light.svg?sanitize=true" width="500" />
|
|
6
6
|
</picture>
|
|
7
7
|
</a>
|
|
8
|
-
<br
|
|
8
|
+
<br />
|
|
9
9
|
<small>A web scraping and browser automation library</small>
|
|
10
10
|
</h1>
|
|
11
11
|
|
|
12
|
-
<p align=center>
|
|
13
|
-
<a href="https://
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
12
|
+
<p align="center">
|
|
13
|
+
<a href="https://trendshift.io/repositories/5179" target="_blank"><img src="https://trendshift.io/api/badge/repositories/5179" alt="apify%2Fcrawlee | Trendshift" width="250" height="55"/></a>
|
|
14
|
+
</p>
|
|
15
|
+
|
|
16
|
+
<p align="center">
|
|
17
|
+
<a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/v/@crawlee/core.svg" alt="NPM latest version" data-canonical-src="https://img.shields.io/npm/v/@crawlee/core/next.svg" /></a>
|
|
18
|
+
<a href="https://www.npmjs.com/package/@crawlee/core" rel="nofollow"><img src="https://img.shields.io/npm/dm/@crawlee/core.svg" alt="Downloads" data-canonical-src="https://img.shields.io/npm/dm/@crawlee/core.svg" /></a>
|
|
19
|
+
<a href="https://discord.gg/jyEM2PRvMU" rel="nofollow"><img src="https://img.shields.io/discord/801163717915574323?label=discord" alt="Chat on discord" data-canonical-src="https://img.shields.io/discord/801163717915574323?label=discord" /></a>
|
|
20
|
+
<a href="https://github.com/apify/crawlee/actions/workflows/test-ci.yml"><img src="https://github.com/apify/crawlee/actions/workflows/test-ci.yml/badge.svg?branch=master" alt="Build Status" /></a>
|
|
17
21
|
</p>
|
|
18
22
|
|
|
19
23
|
Crawlee covers your crawling and scraping end-to-end and **helps you build reliable scrapers. Fast.**
|
|
@@ -24,7 +28,7 @@ Crawlee is available as the [`crawlee`](https://www.npmjs.com/package/crawlee) N
|
|
|
24
28
|
|
|
25
29
|
> 👉 **View full documentation, guides and examples on the [Crawlee project website](https://crawlee.dev)** 👈
|
|
26
30
|
|
|
27
|
-
>
|
|
31
|
+
> Do you prefer 🐍 Python instead of JavaScript? [👉 Checkout Crawlee for Python 👈](https://github.com/apify/crawlee-python).
|
|
28
32
|
|
|
29
33
|
## Installation
|
|
30
34
|
|
|
@@ -85,7 +89,7 @@ By default, Crawlee stores data to `./storage` in the current working directory.
|
|
|
85
89
|
We provide automated beta builds for every merged code change in Crawlee. You can find them in the npm [list of releases](https://www.npmjs.com/package/crawlee?activeTab=versions). If you want to test new features or bug fixes before we release them, feel free to install a beta build like this:
|
|
86
90
|
|
|
87
91
|
```bash
|
|
88
|
-
npm install crawlee@
|
|
92
|
+
npm install crawlee@next
|
|
89
93
|
```
|
|
90
94
|
|
|
91
95
|
If you also use the [Apify SDK](https://github.com/apify/apify-sdk-js), you need to specify dependency overrides in your `package.json` file so that you don't end up with multiple versions of Crawlee installed:
|
|
@@ -94,9 +98,9 @@ If you also use the [Apify SDK](https://github.com/apify/apify-sdk-js), you need
|
|
|
94
98
|
{
|
|
95
99
|
"overrides": {
|
|
96
100
|
"apify": {
|
|
97
|
-
"@crawlee/core": "
|
|
98
|
-
"@crawlee/types": "
|
|
99
|
-
"@crawlee/utils": "
|
|
101
|
+
"@crawlee/core": "$crawlee",
|
|
102
|
+
"@crawlee/types": "$crawlee",
|
|
103
|
+
"@crawlee/utils": "$crawlee"
|
|
100
104
|
}
|
|
101
105
|
}
|
|
102
106
|
}
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* The function must either be labeled `async` or return a promise.
|
|
9
|
-
*/
|
|
10
|
-
runTaskFunction?: () => Promise<unknown>;
|
|
1
|
+
import type { ConcurrencyConsumer, IConcurrencySystem } from './concurrency_system.js';
|
|
2
|
+
import type { CrawleeLogger } from '../log.js';
|
|
3
|
+
/**
|
|
4
|
+
* The two predicates that steer a task loop: *is there work ready?* and *are we done?* These are the parts of the loop
|
|
5
|
+
* a caller legitimately overrides, as opposed to the task itself (`runTaskFunction`), which the loop's driver owns.
|
|
6
|
+
*/
|
|
7
|
+
export interface TaskLoopPredicates {
|
|
11
8
|
/**
|
|
12
9
|
* A function that indicates whether `runTaskFunction` should be called.
|
|
13
10
|
* This function is called every time there is free capacity for a new task and it should
|
|
@@ -17,110 +14,61 @@ export interface AutoscaledPoolOptions {
|
|
|
17
14
|
isTaskReadyFunction?: () => Promise<boolean>;
|
|
18
15
|
/**
|
|
19
16
|
* A function that is called only when there are no tasks to be processed.
|
|
20
|
-
* If it resolves to `true` then the
|
|
17
|
+
* If it resolves to `true` then the run finishes. Being called only
|
|
21
18
|
* when there are no tasks being processed means that as long as `isTaskReadyFunction()`
|
|
22
19
|
* keeps resolving to `true`, `isFinishedFunction()` will never be called.
|
|
23
|
-
* To abort a run, use the {@link AutoscaledPool.abort} method.
|
|
24
20
|
*/
|
|
25
21
|
isFinishedFunction?: () => Promise<boolean>;
|
|
22
|
+
}
|
|
23
|
+
/** @internal */
|
|
24
|
+
export interface AutoscaledPoolOptions extends TaskLoopPredicates {
|
|
26
25
|
/**
|
|
27
|
-
* The
|
|
26
|
+
* The governor that decides whether there is free compute for one more task. Typically a
|
|
27
|
+
* {@link ConcurrencySystem}, but any {@link IConcurrencySystem} works. Share a single instance across
|
|
28
|
+
* multiple pools (and therefore multiple crawlers) to cap their *combined* concurrency against one budget.
|
|
28
29
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @default 1
|
|
32
|
-
*/
|
|
33
|
-
minConcurrency?: number;
|
|
34
|
-
/**
|
|
35
|
-
* The maximum number of tasks running in parallel.
|
|
36
|
-
* @default 200
|
|
30
|
+
* All concurrency/scaling/snapshotter configuration lives on the governor — the pool only owns the task loop and
|
|
31
|
+
* its cadence.
|
|
37
32
|
*/
|
|
38
|
-
|
|
33
|
+
concurrencySystem: IConcurrencySystem;
|
|
39
34
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* By default, it is `minConcurrency`.
|
|
35
|
+
* Who this pool is, presented to the governor on every capacity query and booking so that a shared one can tell
|
|
36
|
+
* several pools apart. Worth naming meaningfully — a governor that allocates per consumer reports this `id`.
|
|
43
37
|
*/
|
|
44
|
-
|
|
38
|
+
consumer: ConcurrencyConsumer;
|
|
45
39
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*/
|
|
49
|
-
desiredConcurrencyRatio?: number;
|
|
50
|
-
/**
|
|
51
|
-
* Defines the fractional amount of desired concurrency to be added with each scaling up.
|
|
52
|
-
* The minimum scaling step is one.
|
|
53
|
-
* @default 0.05
|
|
54
|
-
*/
|
|
55
|
-
scaleUpStepRatio?: number;
|
|
56
|
-
/**
|
|
57
|
-
* Defines the amount of desired concurrency to be subtracted with each scaling down.
|
|
58
|
-
* The minimum scaling step is one.
|
|
59
|
-
* @default 0.05
|
|
40
|
+
* A function that performs an asynchronous resource-intensive task.
|
|
41
|
+
* The function must either be labeled `async` or return a promise.
|
|
60
42
|
*/
|
|
61
|
-
|
|
43
|
+
runTaskFunction?: () => Promise<unknown>;
|
|
62
44
|
/**
|
|
63
45
|
* Indicates how often the pool should call the `runTaskFunction()` to start a new task, in seconds.
|
|
64
46
|
* This has no effect on starting new tasks immediately after a task completes.
|
|
65
47
|
* @default 0.5
|
|
66
48
|
*/
|
|
67
49
|
maybeRunIntervalSecs?: number;
|
|
68
|
-
/**
|
|
69
|
-
* Specifies a period in which the instance logs its state, in seconds.
|
|
70
|
-
* Set to `null` to disable periodic logging.
|
|
71
|
-
* @default 60
|
|
72
|
-
*/
|
|
73
|
-
loggingIntervalSecs?: number | null;
|
|
74
|
-
/**
|
|
75
|
-
* Defines in seconds how often the pool should attempt to adjust the desired concurrency
|
|
76
|
-
* based on the latest system status. Setting it lower than 1 might have a severe impact on performance.
|
|
77
|
-
* We suggest using a value from 5 to 20.
|
|
78
|
-
* @default 10
|
|
79
|
-
*/
|
|
80
|
-
autoscaleIntervalSecs?: number;
|
|
81
50
|
/**
|
|
82
51
|
* Timeout in which the `runTaskFunction` needs to finish, given in seconds.
|
|
83
52
|
* @default 0
|
|
84
53
|
*/
|
|
85
54
|
taskTimeoutSecs?: number;
|
|
86
|
-
|
|
87
|
-
* Options to be passed down to the {@link Snapshotter} constructor. This is useful for fine-tuning
|
|
88
|
-
* the snapshot intervals and history.
|
|
89
|
-
*/
|
|
90
|
-
snapshotterOptions?: SnapshotterOptions;
|
|
91
|
-
/**
|
|
92
|
-
* Options to be passed down to the {@link SystemStatus} constructor. This is useful for fine-tuning
|
|
93
|
-
* the system status reports. If a custom snapshotter is set in the options, it will be used
|
|
94
|
-
* by the pool.
|
|
95
|
-
*/
|
|
96
|
-
systemStatusOptions?: SystemStatusOptions;
|
|
97
|
-
/**
|
|
98
|
-
* The maximum number of tasks per minute the pool can run.
|
|
99
|
-
* By default, this is set to `Infinity`, but you can pass any positive, non-zero integer.
|
|
100
|
-
*/
|
|
101
|
-
maxTasksPerMinute?: number;
|
|
102
|
-
log?: Log;
|
|
55
|
+
log?: CrawleeLogger;
|
|
103
56
|
}
|
|
104
57
|
/**
|
|
105
58
|
* Manages a pool of asynchronous resource-intensive tasks that are executed in parallel.
|
|
106
|
-
* The pool only starts new tasks
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* The information about the CPU and memory usage is obtained by the {@link Snapshotter} class,
|
|
110
|
-
* which makes regular snapshots of system resources that may be either local
|
|
111
|
-
* or from the Apify cloud infrastructure in case the process is running on the Apify platform.
|
|
112
|
-
* Meaningful data gathered from these snapshots is provided to `AutoscaledPool` by the {@link SystemStatus} class.
|
|
59
|
+
* The pool only starts new tasks while its {@link IConcurrencySystem|concurrency system} reports free capacity —
|
|
60
|
+
* that governor is what monitors CPU, memory and event loop load and autoscales the concurrency budget.
|
|
113
61
|
*
|
|
114
62
|
* Before running the pool, you need to implement the following three functions:
|
|
115
|
-
* {@link AutoscaledPoolOptions.runTaskFunction},
|
|
116
|
-
* {@link
|
|
117
|
-
* {@link
|
|
63
|
+
* {@link AutoscaledPoolOptions.runTaskFunction|`runTaskFunction`},
|
|
64
|
+
* {@link TaskLoopPredicates.isTaskReadyFunction|`isTaskReadyFunction`} and
|
|
65
|
+
* {@link TaskLoopPredicates.isFinishedFunction|`isFinishedFunction`}.
|
|
118
66
|
*
|
|
119
67
|
* The auto-scaled pool is started by calling the {@link AutoscaledPool.run} function.
|
|
120
|
-
* The pool periodically queries
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
68
|
+
* The pool periodically queries `isTaskReadyFunction` for more tasks, managing optimal concurrency, until the function
|
|
69
|
+
* resolves to `false`. The pool then queries `isFinishedFunction`. If it resolves to `true`, the run finishes after all
|
|
70
|
+
* running tasks complete. If it resolves to `false`, it assumes there will be more tasks available later and keeps
|
|
71
|
+
* periodically querying for tasks.
|
|
124
72
|
* If any of the tasks throws then the {@link AutoscaledPool.run} function rejects the promise with an error.
|
|
125
73
|
*
|
|
126
74
|
* The pool evaluates whether it should start a new task every time one of the tasks finishes
|
|
@@ -129,8 +77,12 @@ export interface AutoscaledPoolOptions {
|
|
|
129
77
|
* **Example usage:**
|
|
130
78
|
*
|
|
131
79
|
* ```javascript
|
|
80
|
+
* const concurrencySystem = new ConcurrencySystem({ maxConcurrency: 50 });
|
|
81
|
+
* await concurrencySystem.start();
|
|
82
|
+
*
|
|
132
83
|
* const pool = new AutoscaledPool({
|
|
133
|
-
*
|
|
84
|
+
* concurrencySystem,
|
|
85
|
+
* consumer: { id: 'my-pool' },
|
|
134
86
|
* runTaskFunction: async () => {
|
|
135
87
|
* // Run some resource-intensive asynchronous operation here.
|
|
136
88
|
* },
|
|
@@ -145,77 +97,39 @@ export interface AutoscaledPoolOptions {
|
|
|
145
97
|
* }
|
|
146
98
|
* });
|
|
147
99
|
*
|
|
148
|
-
*
|
|
100
|
+
* try {
|
|
101
|
+
* await pool.run();
|
|
102
|
+
* } finally {
|
|
103
|
+
* await concurrencySystem.stop();
|
|
104
|
+
* }
|
|
149
105
|
* ```
|
|
150
|
-
*
|
|
106
|
+
*
|
|
107
|
+
* @internal
|
|
151
108
|
*/
|
|
152
109
|
export declare class AutoscaledPool {
|
|
153
|
-
private
|
|
154
|
-
|
|
155
|
-
private readonly desiredConcurrencyRatio;
|
|
156
|
-
private readonly scaleUpStepRatio;
|
|
157
|
-
private readonly scaleDownStepRatio;
|
|
158
|
-
private readonly maybeRunIntervalMillis;
|
|
159
|
-
private readonly loggingIntervalMillis;
|
|
160
|
-
private readonly autoscaleIntervalMillis;
|
|
161
|
-
private readonly taskTimeoutMillis;
|
|
162
|
-
private readonly runTaskFunction;
|
|
163
|
-
private readonly isFinishedFunction;
|
|
164
|
-
private readonly isTaskReadyFunction;
|
|
165
|
-
private readonly maxTasksPerMinute;
|
|
166
|
-
private _minConcurrency;
|
|
167
|
-
private _maxConcurrency;
|
|
168
|
-
private _desiredConcurrency;
|
|
169
|
-
private _currentConcurrency;
|
|
170
|
-
private isStopped;
|
|
171
|
-
private lastLoggingTime?;
|
|
172
|
-
private resolve;
|
|
173
|
-
private reject;
|
|
174
|
-
private snapshotter;
|
|
175
|
-
private systemStatus;
|
|
176
|
-
private autoscaleInterval;
|
|
177
|
-
private maybeRunInterval;
|
|
178
|
-
private queryingIsTaskReady;
|
|
179
|
-
private queryingIsFinished;
|
|
180
|
-
private tasksDonePerSecondInterval?;
|
|
181
|
-
private _tasksPerMinute;
|
|
182
|
-
constructor(options: AutoscaledPoolOptions, config?: Configuration);
|
|
183
|
-
/**
|
|
184
|
-
* Gets the minimum number of tasks running in parallel.
|
|
185
|
-
*/
|
|
186
|
-
get minConcurrency(): number;
|
|
110
|
+
#private;
|
|
111
|
+
constructor(options: AutoscaledPoolOptions);
|
|
187
112
|
/**
|
|
188
|
-
*
|
|
113
|
+
* The governor backing this pool, as supplied to the constructor — exposed as the read-only
|
|
114
|
+
* {@link IConcurrencySystem} contract.
|
|
189
115
|
*
|
|
190
|
-
*
|
|
191
|
-
*
|
|
192
|
-
*/
|
|
193
|
-
set minConcurrency(value: number);
|
|
194
|
-
/**
|
|
195
|
-
* Gets the maximum number of tasks running in parallel.
|
|
196
|
-
*/
|
|
197
|
-
get maxConcurrency(): number;
|
|
198
|
-
/**
|
|
199
|
-
* Sets the maximum number of tasks running in parallel.
|
|
200
|
-
*/
|
|
201
|
-
set maxConcurrency(value: number);
|
|
202
|
-
/**
|
|
203
|
-
* Gets the desired concurrency for the pool,
|
|
204
|
-
* which is an estimated number of parallel tasks that the system can currently support.
|
|
116
|
+
* This and the two getters below are telemetry only: concurrency is configured and tuned on the concrete
|
|
117
|
+
* {@link ConcurrencySystem} its owner holds, never through the pool.
|
|
205
118
|
*/
|
|
119
|
+
get system(): IConcurrencySystem;
|
|
120
|
+
/** The estimated number of parallel tasks the governor can currently support. */
|
|
206
121
|
get desiredConcurrency(): number;
|
|
207
122
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*/
|
|
211
|
-
set desiredConcurrency(value: number);
|
|
212
|
-
/**
|
|
213
|
-
* Gets the number of parallel tasks currently running in the pool.
|
|
123
|
+
* The number of parallel tasks currently booked against the governor. When it is shared, this counts every
|
|
124
|
+
* borrowing pool's tasks, not just this one's.
|
|
214
125
|
*/
|
|
215
126
|
get currentConcurrency(): number;
|
|
216
127
|
/**
|
|
217
128
|
* Runs the auto-scaled pool. Returns a promise that gets resolved or rejected once
|
|
218
129
|
* all the tasks are finished or one of them fails.
|
|
130
|
+
*
|
|
131
|
+
* Throws if the {@link IConcurrencySystem|concurrency system} it borrows was never started — the pool assumes
|
|
132
|
+
* a running governor and cannot start one it does not own.
|
|
219
133
|
*/
|
|
220
134
|
run(): Promise<void>;
|
|
221
135
|
/**
|
|
@@ -240,6 +154,10 @@ export declare class AutoscaledPool {
|
|
|
240
154
|
*
|
|
241
155
|
* The promise returned from the {@link AutoscaledPool.run} function will not resolve
|
|
242
156
|
* when `.pause()` is invoked (unlike abort, which resolves it).
|
|
157
|
+
*
|
|
158
|
+
* > *NOTE:* Pausing the pool does not suspend the (possibly shared) {@link ConcurrencySystem} — its
|
|
159
|
+
* autoscaling and resource monitoring keep running, since other pools borrowing it may still be active. To silence
|
|
160
|
+
* it during a long pause, its owner can `stop()` and `start()` it again.
|
|
243
161
|
*/
|
|
244
162
|
pause(timeoutSecs?: number): Promise<void>;
|
|
245
163
|
/**
|
|
@@ -258,43 +176,20 @@ export declare class AutoscaledPool {
|
|
|
258
176
|
* Starts a new task
|
|
259
177
|
* if the number of running tasks (current concurrency) is lower than desired concurrency
|
|
260
178
|
* and the system is not currently overloaded
|
|
261
|
-
* and
|
|
179
|
+
* and `isTaskReadyFunction()` returns true.
|
|
262
180
|
*
|
|
263
181
|
* It doesn't allow multiple concurrent runs of this method.
|
|
264
182
|
*/
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Gets called every autoScaleIntervalSecs and evaluates the current system status.
|
|
268
|
-
* If the system IS NOT overloaded and the settings allow it, it scales up.
|
|
269
|
-
* If the system IS overloaded and the settings allow it, it scales down.
|
|
270
|
-
*/
|
|
271
|
-
protected _autoscale(intervalCallback: () => void): void;
|
|
272
|
-
/**
|
|
273
|
-
* Scales the pool up by increasing
|
|
274
|
-
* the desired concurrency by the scaleUpStepRatio.
|
|
275
|
-
*
|
|
276
|
-
* @param systemStatus for logging
|
|
277
|
-
*/
|
|
278
|
-
protected _scaleUp(systemStatus: SystemInfo): void;
|
|
279
|
-
/**
|
|
280
|
-
* Scales the pool down by decreasing
|
|
281
|
-
* the desired concurrency by the scaleDownStepRatio.
|
|
282
|
-
*
|
|
283
|
-
* @param systemStatus for logging
|
|
284
|
-
*/
|
|
285
|
-
protected _scaleDown(systemStatus: SystemInfo): void;
|
|
183
|
+
private maybeRunTask;
|
|
286
184
|
/**
|
|
287
|
-
* If there are no running tasks and
|
|
185
|
+
* If there are no running tasks and `isFinishedFunction()` returns true then closes
|
|
288
186
|
* the pool and resolves the pool's promise returned by the run() method.
|
|
289
187
|
*
|
|
290
188
|
* It doesn't allow multiple concurrent runs of this method.
|
|
291
189
|
*/
|
|
292
|
-
|
|
190
|
+
private maybeFinish;
|
|
293
191
|
/**
|
|
294
192
|
* Cleans up resources.
|
|
295
193
|
*/
|
|
296
|
-
|
|
297
|
-
protected _incrementTasksDonePerSecond(intervalCallback: () => void): void;
|
|
298
|
-
protected get _isOverMaxRequestLimit(): boolean;
|
|
194
|
+
private destroy;
|
|
299
195
|
}
|
|
300
|
-
//# sourceMappingURL=autoscaled_pool.d.ts.map
|