@crawlee/core 4.0.0-beta.9 → 4.0.0-beta.91
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 +66 -153
- package/autoscaling/autoscaled_pool.js +95 -251
- package/autoscaling/client_load_signal.d.ts +59 -0
- package/autoscaling/client_load_signal.js +73 -0
- package/autoscaling/concurrency_system.d.ts +283 -0
- package/autoscaling/concurrency_system.js +350 -0
- package/autoscaling/cpu_load_signal.d.ts +44 -0
- package/autoscaling/cpu_load_signal.js +46 -0
- package/autoscaling/event_loop_load_signal.d.ts +54 -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 +99 -0
- package/autoscaling/load_signal.js +103 -0
- package/autoscaling/memory_load_signal.d.ts +56 -0
- package/autoscaling/memory_load_signal.js +106 -0
- package/autoscaling/snapshotter.d.ts +61 -163
- package/autoscaling/snapshotter.js +45 -263
- package/autoscaling/system_status.d.ts +63 -83
- package/autoscaling/system_status.js +90 -120
- package/configuration.d.ts +90 -223
- package/configuration.js +164 -222
- package/cookie_utils.d.ts +4 -3
- package/cookie_utils.js +20 -13
- package/crawlers/context_pipeline.d.ts +70 -0
- package/crawlers/context_pipeline.js +122 -0
- package/crawlers/crawler_commons.d.ts +76 -33
- package/crawlers/crawler_commons.js +15 -24
- package/crawlers/crawler_utils.d.ts +2 -3
- package/crawlers/crawler_utils.js +1 -2
- package/crawlers/error_snapshotter.d.ts +3 -3
- package/crawlers/error_snapshotter.js +2 -3
- package/crawlers/error_tracker.d.ts +2 -2
- package/crawlers/error_tracker.js +0 -1
- package/crawlers/index.d.ts +1 -2
- package/crawlers/index.js +1 -2
- package/crawlers/internals/types.d.ts +7 -0
- package/crawlers/internals/types.js +1 -0
- package/crawlers/statistics.d.ts +28 -23
- package/crawlers/statistics.js +38 -34
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/enqueue_links/enqueue_links.d.ts +44 -22
- package/enqueue_links/enqueue_links.js +51 -30
- package/enqueue_links/index.d.ts +0 -1
- package/enqueue_links/index.js +0 -1
- package/enqueue_links/shared.d.ts +25 -9
- package/enqueue_links/shared.js +69 -38
- package/errors.d.ts +53 -4
- package/errors.js +70 -5
- package/events/event_manager.d.ts +34 -8
- package/events/event_manager.js +8 -10
- 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 +37 -11
- package/index.d.ts +6 -3
- package/index.js +5 -2
- package/log.d.ts +82 -3
- package/log.js +102 -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 +46 -0
- package/memory-storage/memory-storage.js +136 -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 +113 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
- package/memory-storage/resource-clients/key-value-store.js +203 -0
- package/memory-storage/resource-clients/request-queue.d.ts +96 -0
- package/memory-storage/resource-clients/request-queue.js +421 -0
- package/memory-storage/utils.d.ts +17 -0
- package/memory-storage/utils.js +42 -0
- package/owned_or_injected.d.ts +60 -0
- package/owned_or_injected.js +98 -0
- package/package.json +12 -10
- package/proxy_configuration.d.ts +29 -152
- package/proxy_configuration.js +21 -173
- package/recoverable_state.d.ts +120 -0
- package/recoverable_state.js +143 -0
- package/request.d.ts +85 -15
- package/request.js +107 -28
- package/router.d.ts +144 -19
- package/router.js +125 -30
- package/serialization.d.ts +0 -1
- package/serialization.js +1 -2
- package/service_locator.d.ts +156 -0
- package/service_locator.js +238 -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 +37 -75
- package/session_pool/session.js +49 -102
- package/session_pool/session_pool.d.ts +85 -90
- package/session_pool/session_pool.js +131 -120
- package/storages/access_checking.d.ts +1 -2
- package/storages/access_checking.js +5 -2
- package/storages/dataset.d.ts +103 -54
- package/storages/dataset.js +174 -132
- package/storages/index.d.ts +8 -7
- package/storages/index.js +6 -7
- package/storages/key_value_store.d.ts +167 -39
- package/storages/key_value_store.js +274 -127
- 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 +23 -0
- package/storages/request_dedup_cache.js +48 -0
- package/storages/request_list.d.ts +54 -98
- package/storages/request_list.js +99 -75
- package/storages/request_loader.d.ts +96 -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 +106 -0
- package/storages/request_manager_tandem.js +197 -0
- package/storages/request_queue.d.ts +290 -47
- package/storages/request_queue.js +629 -215
- package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +28 -24
- package/storages/{sitemap_request_list.js → sitemap_request_loader.js} +49 -47
- package/storages/storage_instance_manager.d.ts +90 -0
- package/storages/storage_instance_manager.js +258 -0
- package/storages/storage_stats.d.ts +48 -0
- package/storages/storage_stats.js +29 -0
- package/storages/utils.d.ts +54 -9
- package/storages/utils.js +64 -13
- 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/validators.d.ts +8 -1
- package/validators.js +10 -3
- 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/crawler_commons.d.ts.map +0 -1
- package/crawlers/crawler_commons.js.map +0 -1
- package/crawlers/crawler_extension.d.ts +0 -12
- package/crawlers/crawler_extension.d.ts.map +0 -1
- package/crawlers/crawler_extension.js +0 -14
- package/crawlers/crawler_extension.js.map +0 -1
- package/crawlers/crawler_utils.d.ts.map +0 -1
- 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/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 -134
- package/http_clients/base-http-client.d.ts.map +0 -1
- package/http_clients/base-http-client.js +0 -33
- 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 -15
- package/http_clients/got-scraping-http-client.d.ts.map +0 -1
- package/http_clients/got-scraping-http-client.js +0 -69
- 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.map +0 -1
- 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 -307
- 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.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,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
runTaskFunction?: () => Promise<unknown>;
|
|
1
|
+
import type { ConcurrencyConsumer, IConcurrencySystem } from './concurrency_system.js';
|
|
2
|
+
import type { CrawleeLogger } from '../log.js';
|
|
3
|
+
/**
|
|
4
|
+
* The task-readiness predicates a consumer may supply to steer an {@link AutoscaledPool}'s run loop — the parts of
|
|
5
|
+
* the loop a higher-level driver (e.g. a crawler) legitimately overrides, as opposed to the crawler-owned
|
|
6
|
+
* `runTaskFunction`.
|
|
7
|
+
*/
|
|
8
|
+
export interface AutoscaledPoolPredicateOptions {
|
|
11
9
|
/**
|
|
12
10
|
* A function that indicates whether `runTaskFunction` should be called.
|
|
13
11
|
* This function is called every time there is free capacity for a new task and it should
|
|
@@ -23,104 +21,55 @@ export interface AutoscaledPoolOptions {
|
|
|
23
21
|
* To abort a run, use the {@link AutoscaledPool.abort} method.
|
|
24
22
|
*/
|
|
25
23
|
isFinishedFunction?: () => Promise<boolean>;
|
|
24
|
+
}
|
|
25
|
+
export interface AutoscaledPoolOptions extends AutoscaledPoolPredicateOptions {
|
|
26
26
|
/**
|
|
27
|
-
* The
|
|
27
|
+
* The governor that decides whether there is free compute for one more task. Typically a
|
|
28
|
+
* {@link ConcurrencySystem}, but any {@link IConcurrencySystem} works. Share a single instance across
|
|
29
|
+
* multiple pools (and therefore multiple crawlers) to cap their *combined* concurrency against one budget.
|
|
28
30
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* @default 1
|
|
32
|
-
*/
|
|
33
|
-
minConcurrency?: number;
|
|
34
|
-
/**
|
|
35
|
-
* The maximum number of tasks running in parallel.
|
|
36
|
-
* @default 200
|
|
37
|
-
*/
|
|
38
|
-
maxConcurrency?: number;
|
|
39
|
-
/**
|
|
40
|
-
* The desired number of tasks that should be running parallel on the start of the pool,
|
|
41
|
-
* if there is a large enough supply of them.
|
|
42
|
-
* By default, it is `minConcurrency`.
|
|
31
|
+
* All concurrency/scaling/snapshotter configuration lives on the governor — the pool only owns the task loop and
|
|
32
|
+
* its cadence.
|
|
43
33
|
*/
|
|
44
|
-
|
|
34
|
+
concurrencySystem: IConcurrencySystem;
|
|
45
35
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
36
|
+
* Who this pool is, presented to the governor on every capacity query and booking so that a shared one can tell
|
|
37
|
+
* several pools apart. Worth naming meaningfully — a governor that allocates per consumer reports this `id`.
|
|
48
38
|
*/
|
|
49
|
-
|
|
39
|
+
consumer: ConcurrencyConsumer;
|
|
50
40
|
/**
|
|
51
|
-
*
|
|
52
|
-
* The
|
|
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
|
|
41
|
+
* A function that performs an asynchronous resource-intensive task.
|
|
42
|
+
* The function must either be labeled `async` or return a promise.
|
|
60
43
|
*/
|
|
61
|
-
|
|
44
|
+
runTaskFunction?: () => Promise<unknown>;
|
|
62
45
|
/**
|
|
63
46
|
* Indicates how often the pool should call the `runTaskFunction()` to start a new task, in seconds.
|
|
64
47
|
* This has no effect on starting new tasks immediately after a task completes.
|
|
65
48
|
* @default 0.5
|
|
66
49
|
*/
|
|
67
50
|
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
51
|
/**
|
|
82
52
|
* Timeout in which the `runTaskFunction` needs to finish, given in seconds.
|
|
83
53
|
* @default 0
|
|
84
54
|
*/
|
|
85
55
|
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;
|
|
56
|
+
log?: CrawleeLogger;
|
|
103
57
|
}
|
|
104
58
|
/**
|
|
105
59
|
* 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.
|
|
60
|
+
* The pool only starts new tasks while its {@link IConcurrencySystem|concurrency system} reports free capacity —
|
|
61
|
+
* that governor is what monitors CPU, memory and event loop load and autoscales the concurrency budget.
|
|
113
62
|
*
|
|
114
63
|
* Before running the pool, you need to implement the following three functions:
|
|
115
|
-
* {@link AutoscaledPoolOptions.runTaskFunction},
|
|
116
|
-
* {@link
|
|
117
|
-
* {@link
|
|
64
|
+
* {@link AutoscaledPoolOptions.runTaskFunction|`runTaskFunction`},
|
|
65
|
+
* {@link AutoscaledPoolPredicateOptions.isTaskReadyFunction|`isTaskReadyFunction`} and
|
|
66
|
+
* {@link AutoscaledPoolPredicateOptions.isFinishedFunction|`isFinishedFunction`}.
|
|
118
67
|
*
|
|
119
68
|
* The auto-scaled pool is started by calling the {@link AutoscaledPool.run} function.
|
|
120
|
-
* The pool periodically queries
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
69
|
+
* The pool periodically queries `isTaskReadyFunction` for more tasks, managing optimal concurrency, until the function
|
|
70
|
+
* resolves to `false`. The pool then queries `isFinishedFunction`. If it resolves to `true`, the run finishes after all
|
|
71
|
+
* running tasks complete. If it resolves to `false`, it assumes there will be more tasks available later and keeps
|
|
72
|
+
* periodically querying for tasks.
|
|
124
73
|
* If any of the tasks throws then the {@link AutoscaledPool.run} function rejects the promise with an error.
|
|
125
74
|
*
|
|
126
75
|
* The pool evaluates whether it should start a new task every time one of the tasks finishes
|
|
@@ -129,8 +78,12 @@ export interface AutoscaledPoolOptions {
|
|
|
129
78
|
* **Example usage:**
|
|
130
79
|
*
|
|
131
80
|
* ```javascript
|
|
81
|
+
* const concurrencySystem = new ConcurrencySystem({ maxConcurrency: 50 });
|
|
82
|
+
* await concurrencySystem.start();
|
|
83
|
+
*
|
|
132
84
|
* const pool = new AutoscaledPool({
|
|
133
|
-
*
|
|
85
|
+
* concurrencySystem,
|
|
86
|
+
* consumer: { id: 'my-pool' },
|
|
134
87
|
* runTaskFunction: async () => {
|
|
135
88
|
* // Run some resource-intensive asynchronous operation here.
|
|
136
89
|
* },
|
|
@@ -145,77 +98,56 @@ export interface AutoscaledPoolOptions {
|
|
|
145
98
|
* }
|
|
146
99
|
* });
|
|
147
100
|
*
|
|
148
|
-
*
|
|
101
|
+
* try {
|
|
102
|
+
* await pool.run();
|
|
103
|
+
* } finally {
|
|
104
|
+
* await concurrencySystem.stop();
|
|
105
|
+
* }
|
|
149
106
|
* ```
|
|
150
107
|
* @category Scaling
|
|
151
108
|
*/
|
|
152
109
|
export declare class AutoscaledPool {
|
|
153
|
-
private readonly config;
|
|
154
110
|
private readonly log;
|
|
155
|
-
private readonly desiredConcurrencyRatio;
|
|
156
|
-
private readonly scaleUpStepRatio;
|
|
157
|
-
private readonly scaleDownStepRatio;
|
|
158
111
|
private readonly maybeRunIntervalMillis;
|
|
159
|
-
private readonly loggingIntervalMillis;
|
|
160
|
-
private readonly autoscaleIntervalMillis;
|
|
161
112
|
private readonly taskTimeoutMillis;
|
|
162
113
|
private readonly runTaskFunction;
|
|
163
114
|
private readonly isFinishedFunction;
|
|
164
115
|
private readonly isTaskReadyFunction;
|
|
165
|
-
private readonly
|
|
166
|
-
private
|
|
167
|
-
private _maxConcurrency;
|
|
168
|
-
private _desiredConcurrency;
|
|
169
|
-
private _currentConcurrency;
|
|
116
|
+
private readonly concurrencySystem;
|
|
117
|
+
private readonly consumer;
|
|
170
118
|
private isStopped;
|
|
171
|
-
private lastLoggingTime?;
|
|
172
119
|
private resolve;
|
|
173
120
|
private reject;
|
|
174
|
-
private snapshotter;
|
|
175
|
-
private systemStatus;
|
|
176
|
-
private autoscaleInterval;
|
|
177
121
|
private maybeRunInterval;
|
|
178
122
|
private queryingIsTaskReady;
|
|
179
123
|
private queryingIsFinished;
|
|
180
|
-
private tasksDonePerSecondInterval?;
|
|
181
|
-
private _tasksPerMinute;
|
|
182
|
-
constructor(options: AutoscaledPoolOptions, config?: Configuration);
|
|
183
124
|
/**
|
|
184
|
-
*
|
|
125
|
+
* This pool's *own* in-flight task count, as opposed to {@link AutoscaledPool.currentConcurrency}, which is the
|
|
126
|
+
* (possibly shared) governor's total. `pause()` and `maybeFinish()` care only about this pool draining.
|
|
185
127
|
*/
|
|
186
|
-
|
|
128
|
+
private ownConcurrency;
|
|
129
|
+
constructor(options: AutoscaledPoolOptions);
|
|
187
130
|
/**
|
|
188
|
-
*
|
|
131
|
+
* The governor backing this pool, as supplied to the constructor — exposed as the read-only
|
|
132
|
+
* {@link IConcurrencySystem} contract.
|
|
189
133
|
*
|
|
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.
|
|
134
|
+
* This and the two getters below are telemetry only: concurrency is configured and tuned on the concrete
|
|
135
|
+
* {@link ConcurrencySystem} its owner holds, never through the pool.
|
|
205
136
|
*/
|
|
137
|
+
get system(): IConcurrencySystem;
|
|
138
|
+
/** The estimated number of parallel tasks the governor can currently support. */
|
|
206
139
|
get desiredConcurrency(): number;
|
|
207
140
|
/**
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*/
|
|
211
|
-
set desiredConcurrency(value: number);
|
|
212
|
-
/**
|
|
213
|
-
* Gets the number of parallel tasks currently running in the pool.
|
|
141
|
+
* The number of parallel tasks currently booked against the governor. When it is shared, this counts every
|
|
142
|
+
* borrowing pool's tasks, not just this one's.
|
|
214
143
|
*/
|
|
215
144
|
get currentConcurrency(): number;
|
|
216
145
|
/**
|
|
217
146
|
* Runs the auto-scaled pool. Returns a promise that gets resolved or rejected once
|
|
218
147
|
* all the tasks are finished or one of them fails.
|
|
148
|
+
*
|
|
149
|
+
* Throws if the {@link IConcurrencySystem|concurrency system} it borrows was never started — the pool assumes
|
|
150
|
+
* a running governor and cannot start one it does not own.
|
|
219
151
|
*/
|
|
220
152
|
run(): Promise<void>;
|
|
221
153
|
/**
|
|
@@ -240,6 +172,10 @@ export declare class AutoscaledPool {
|
|
|
240
172
|
*
|
|
241
173
|
* The promise returned from the {@link AutoscaledPool.run} function will not resolve
|
|
242
174
|
* when `.pause()` is invoked (unlike abort, which resolves it).
|
|
175
|
+
*
|
|
176
|
+
* > *NOTE:* Pausing the pool does not suspend the (possibly shared) {@link ConcurrencySystem} — its
|
|
177
|
+
* autoscaling and resource monitoring keep running, since other pools borrowing it may still be active. To silence
|
|
178
|
+
* it during a long pause, its owner can `stop()` and `start()` it again.
|
|
243
179
|
*/
|
|
244
180
|
pause(timeoutSecs?: number): Promise<void>;
|
|
245
181
|
/**
|
|
@@ -262,39 +198,16 @@ export declare class AutoscaledPool {
|
|
|
262
198
|
*
|
|
263
199
|
* It doesn't allow multiple concurrent runs of this method.
|
|
264
200
|
*/
|
|
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;
|
|
201
|
+
private maybeRunTask;
|
|
286
202
|
/**
|
|
287
203
|
* If there are no running tasks and this.isFinishedFunction() returns true then closes
|
|
288
204
|
* the pool and resolves the pool's promise returned by the run() method.
|
|
289
205
|
*
|
|
290
206
|
* It doesn't allow multiple concurrent runs of this method.
|
|
291
207
|
*/
|
|
292
|
-
|
|
208
|
+
private maybeFinish;
|
|
293
209
|
/**
|
|
294
210
|
* Cleans up resources.
|
|
295
211
|
*/
|
|
296
|
-
|
|
297
|
-
protected _incrementTasksDonePerSecond(intervalCallback: () => void): void;
|
|
298
|
-
protected get _isOverMaxRequestLimit(): boolean;
|
|
212
|
+
private destroy;
|
|
299
213
|
}
|
|
300
|
-
//# sourceMappingURL=autoscaled_pool.d.ts.map
|