@crawlee/core 4.0.0-beta.15 → 4.0.0-beta.150
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 +14 -14
- package/autoscaling/autoscaled_pool.d.ts +73 -177
- package/autoscaling/autoscaled_pool.js +182 -329
- package/autoscaling/concurrency_system.d.ts +268 -0
- package/autoscaling/concurrency_system.js +364 -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 +98 -0
- package/autoscaling/load_signal.js +103 -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 -126
- package/crawlers/crawler_commons.js +1 -108
- 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 -64
- package/crawlers/statistics.js +354 -165
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/enqueue_links/enqueue_links.d.ts +61 -154
- package/enqueue_links/enqueue_links.js +40 -232
- package/enqueue_links/index.d.ts +0 -1
- package/enqueue_links/index.js +0 -1
- package/enqueue_links/shared.d.ts +55 -28
- package/enqueue_links/shared.js +116 -69
- 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 -5
- package/index.js +8 -4
- package/iterables.d.ts +79 -0
- package/iterables.js +134 -0
- package/log.d.ts +77 -1
- package/log.js +104 -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 +44 -0
- package/memory-storage/memory-storage.js +160 -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 +106 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
- package/memory-storage/resource-clients/key-value-store.js +199 -0
- package/memory-storage/resource-clients/request-queue.d.ts +77 -0
- package/memory-storage/resource-clients/request-queue.js +407 -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 +13 -12
- package/proxy_configuration.d.ts +22 -128
- package/proxy_configuration.js +32 -144
- package/recoverable_state.d.ts +83 -51
- package/recoverable_state.js +163 -72
- package/request.d.ts +57 -16
- package/request.js +130 -69
- 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 +39 -89
- package/session_pool/session.js +102 -159
- package/session_pool/session_pool.d.ts +67 -91
- package/session_pool/session_pool.js +196 -187
- package/storages/batched_adds.d.ts +37 -0
- package/storages/batched_adds.js +73 -0
- package/storages/dataset.d.ts +109 -56
- package/storages/dataset.js +284 -149
- package/storages/index.d.ts +9 -9
- package/storages/index.js +7 -9
- package/storages/key_value_store.d.ts +183 -48
- package/storages/key_value_store.js +444 -171
- 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 +53 -115
- package/storages/request_list.js +194 -167
- package/storages/request_loader.d.ts +133 -0
- package/storages/request_loader.js +36 -0
- package/storages/request_manager.d.ts +109 -0
- package/storages/request_manager.js +1 -0
- package/storages/request_manager_tandem.d.ts +55 -23
- package/storages/request_manager_tandem.js +139 -57
- package/storages/request_queue.d.ts +286 -48
- package/storages/request_queue.js +757 -218
- package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +43 -91
- package/storages/sitemap_request_loader.js +439 -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 +222 -0
- package/storages/throttling_request_manager.js +780 -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 -85
- 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/recoverable_state.d.ts.map +0 -1
- package/recoverable_state.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_list_adapter.d.ts +0 -58
- package/storages/request_list_adapter.d.ts.map +0 -1
- package/storages/request_list_adapter.js +0 -81
- package/storages/request_list_adapter.js.map +0 -1
- package/storages/request_manager_tandem.d.ts.map +0 -1
- package/storages/request_manager_tandem.js.map +0 -1
- package/storages/request_provider.d.ts +0 -371
- package/storages/request_provider.d.ts.map +0 -1
- package/storages/request_provider.js +0 -585
- 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/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
|
@@ -1,8 +1,15 @@
|
|
|
1
|
-
import type { Dictionary } from '@crawlee/types';
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
5
|
-
import {
|
|
1
|
+
import type { BatchAddRequestsResult, Dictionary, ProcessedRequest, QueueOperationInfo, RequestQueueBackend, RequestQueueInfo } from '@crawlee/types';
|
|
2
|
+
import type { ReadonlyDeep } from 'type-fest';
|
|
3
|
+
import type { CrawleeLogger } from '../log.js';
|
|
4
|
+
import type { IProxyConfiguration } from '../proxy_configuration.js';
|
|
5
|
+
import type { Source } from '../request.js';
|
|
6
|
+
import { Request } from '../request.js';
|
|
7
|
+
import type { JournalEntry } from './transaction.js';
|
|
8
|
+
import type { RequestLoaderStatus } from './request_loader.js';
|
|
9
|
+
import type { IRequestManager, PacingSignal, RequestsLike } from './request_manager.js';
|
|
10
|
+
import type { RequestQueueStats } from './storage_stats.js';
|
|
11
|
+
import type { IStorage, StorageIdentifier } from './storage_instance_manager.js';
|
|
12
|
+
import type { StorageOpenOptions } from './utils.js';
|
|
6
13
|
/**
|
|
7
14
|
* Represents a queue of URLs to crawl, which is used for deep crawling of websites
|
|
8
15
|
* where you start with several URLs and then recursively
|
|
@@ -21,18 +28,6 @@ import { RequestProvider } from './request_provider.js';
|
|
|
21
28
|
* Unlike {@link RequestList}, `RequestQueue` supports dynamic adding and removing of requests.
|
|
22
29
|
* On the other hand, the queue is not optimized for operations that add or remove a large number of URLs in a batch.
|
|
23
30
|
*
|
|
24
|
-
* `RequestQueue` stores its data either on local disk or in the Apify Cloud,
|
|
25
|
-
* depending on whether the `APIFY_LOCAL_STORAGE_DIR` or `APIFY_TOKEN` environment variable is set.
|
|
26
|
-
*
|
|
27
|
-
* If the `APIFY_LOCAL_STORAGE_DIR` environment variable is set, the queue data is stored in
|
|
28
|
-
* that directory in an SQLite database file.
|
|
29
|
-
*
|
|
30
|
-
* If the `APIFY_TOKEN` environment variable is set but `APIFY_LOCAL_STORAGE_DIR` is not, the data is stored in the
|
|
31
|
-
* [Apify Request Queue](https://docs.apify.com/storage/request-queue)
|
|
32
|
-
* cloud storage. Note that you can force usage of the cloud storage also by passing the `forceCloud`
|
|
33
|
-
* option to {@link RequestQueue.open} function,
|
|
34
|
-
* even if the `APIFY_LOCAL_STORAGE_DIR` variable is set.
|
|
35
|
-
*
|
|
36
31
|
* **Example usage:**
|
|
37
32
|
*
|
|
38
33
|
* ```javascript
|
|
@@ -48,25 +43,104 @@ import { RequestProvider } from './request_provider.js';
|
|
|
48
43
|
* await queue.addRequest({ url: 'http://example.com/foo/bar' }, { forefront: true });
|
|
49
44
|
* ```
|
|
50
45
|
* @category Sources
|
|
51
|
-
*
|
|
52
|
-
* @deprecated RequestQueue v1 is deprecated and will be removed in the future. Please use {@link RequestQueue} instead.
|
|
53
46
|
*/
|
|
54
|
-
declare class RequestQueue
|
|
55
|
-
private
|
|
56
|
-
|
|
47
|
+
export declare class RequestQueue implements IStorage, IRequestManager {
|
|
48
|
+
#private;
|
|
49
|
+
readonly id: string;
|
|
50
|
+
readonly name?: string;
|
|
51
|
+
readonly backend: RequestQueueBackend;
|
|
52
|
+
readonly log: CrawleeLogger;
|
|
57
53
|
/**
|
|
58
|
-
*
|
|
54
|
+
* Backend-independent usage counters tracked for this request queue (write operations and
|
|
55
|
+
* queue-head reads issued to the underlying storage backend). Counted per backend call.
|
|
59
56
|
*/
|
|
60
|
-
|
|
57
|
+
get stats(): RequestQueueStats;
|
|
61
58
|
/**
|
|
62
59
|
* @internal
|
|
63
60
|
*/
|
|
64
|
-
|
|
61
|
+
constructor(options: RequestQueueOptions);
|
|
62
|
+
/**
|
|
63
|
+
* Returns the total number of requests in the queue (i.e. pending + handled).
|
|
64
|
+
*
|
|
65
|
+
* Survives restarts and actor migrations.
|
|
66
|
+
*/
|
|
67
|
+
getTotalCount(): Promise<number>;
|
|
68
|
+
/**
|
|
69
|
+
* Returns the total number of pending requests in the queue.
|
|
70
|
+
*
|
|
71
|
+
* Survives restarts and Actor migrations.
|
|
72
|
+
*/
|
|
73
|
+
getPendingCount(): Promise<number>;
|
|
74
|
+
/**
|
|
75
|
+
* Adds a request to the queue.
|
|
76
|
+
*
|
|
77
|
+
* If a request with the same `uniqueKey` property is already present in the queue,
|
|
78
|
+
* it will not be updated. You can find out whether this happened from the resulting
|
|
79
|
+
* {@link QueueOperationInfo} object.
|
|
80
|
+
*
|
|
81
|
+
* To add multiple requests to the queue by extracting links from a webpage,
|
|
82
|
+
* see the {@link enqueueLinks} helper function.
|
|
83
|
+
*
|
|
84
|
+
* @param requestLike {@link Request} object or vanilla object with request data.
|
|
85
|
+
* Note that the function sets the `uniqueKey` and `id` fields to the passed Request.
|
|
86
|
+
* @param [options] Request queue operation options.
|
|
87
|
+
*/
|
|
88
|
+
addRequest(requestLike: Source, options?: RequestQueueOperationOptions): Promise<RequestQueueOperationInfo>;
|
|
89
|
+
/**
|
|
90
|
+
* Journals an addition for introspection only; these entries are never replayed. A no-op unless the
|
|
91
|
+
* transaction is open, so detached and outliving writers stay out of the journal.
|
|
92
|
+
*/
|
|
93
|
+
private recordRequestJournalEntry;
|
|
94
|
+
/**
|
|
95
|
+
* The requests buffered by the given transaction for this queue, keyed by `uniqueKey` — a dedup
|
|
96
|
+
* index derived from the transaction journal.
|
|
97
|
+
*/
|
|
98
|
+
private bufferedRequests;
|
|
99
|
+
/**
|
|
100
|
+
* Adds a request under the `deferred` policy: journaled now, really added by the commit replay.
|
|
101
|
+
* A new request's `requestId` is the local `uniqueKey` hash and is **provisional** — never write it
|
|
102
|
+
* to `request.id` or the dedup caches. Dedup is cheapest-first: buffer, caches, then a backend probe.
|
|
103
|
+
*/
|
|
104
|
+
private addRequestDeferred;
|
|
105
|
+
/** @internal */
|
|
106
|
+
commitJournalEntries(entries: JournalEntry[]): Promise<void>;
|
|
107
|
+
/**
|
|
108
|
+
* Adds requests to the queue in batches of 25. This method will wait till all the requests are added
|
|
109
|
+
* to the queue before resolving. You should prefer using `queue.addRequestsBatched()` or `crawler.addRequests()`
|
|
110
|
+
* if you don't want to block the processing, as those methods will only wait for the initial 1000 requests,
|
|
111
|
+
* start processing right after that happens, and continue adding more in the background.
|
|
112
|
+
*
|
|
113
|
+
* If a request passed in is already present due to its `uniqueKey` property being the same,
|
|
114
|
+
* it will not be updated. You can find out whether this happened by finding the request in the resulting
|
|
115
|
+
* {@link BatchAddRequestsResult} object.
|
|
116
|
+
*
|
|
117
|
+
* @param requestsLike {@link Request} objects or vanilla objects with request data.
|
|
118
|
+
* Note that the function sets the `uniqueKey` and `id` fields to the passed requests if missing.
|
|
119
|
+
* @param [options] Request queue operation options.
|
|
120
|
+
*/
|
|
121
|
+
addRequests(requestsLike: RequestsLike, options?: RequestQueueOperationOptions): Promise<BatchAddRequestsResult>;
|
|
122
|
+
/**
|
|
123
|
+
* Adds requests to the queue in batches. By default, it will resolve after the initial batch is added, and continue
|
|
124
|
+
* adding the rest in the background. You can configure the batch size via `batchSize` option and the sleep time in between
|
|
125
|
+
* the batches via `waitBetweenBatchesMillis`. If you want to wait for all batches to be added to the queue, you can use
|
|
126
|
+
* the `waitForAllRequestsToBeAdded` promise you get in the response object.
|
|
127
|
+
*
|
|
128
|
+
* @param requests The requests to add
|
|
129
|
+
* @param options Options for the request queue
|
|
130
|
+
*/
|
|
131
|
+
addRequestsBatched(requests: ReadonlyDeep<RequestsLike>, options?: AddRequestsBatchedOptions): Promise<AddRequestsBatchedResult>;
|
|
132
|
+
/**
|
|
133
|
+
* Gets the request from the queue specified by its `uniqueKey`.
|
|
134
|
+
*
|
|
135
|
+
* @param uniqueKey Unique key of the request.
|
|
136
|
+
* @returns Returns the request object, or `null` if it was not found.
|
|
137
|
+
*/
|
|
138
|
+
getRequest<T extends Dictionary = Dictionary>(uniqueKey: string): Promise<Request<T> | null>;
|
|
65
139
|
/**
|
|
66
140
|
* Returns a next request in the queue to be processed, or `null` if there are no more pending requests.
|
|
67
141
|
*
|
|
68
142
|
* Once you successfully finish processing of the request, you need to call
|
|
69
|
-
* {@link RequestQueue.
|
|
143
|
+
* {@link RequestQueue.markRequestAsHandled}
|
|
70
144
|
* to mark the request as handled in the queue. If there was some error in processing the request,
|
|
71
145
|
* call {@link RequestQueue.reclaimRequest} instead,
|
|
72
146
|
* so that the queue will give the request to some other consumer in another call to the `fetchNextRequest` function.
|
|
@@ -74,38 +148,114 @@ declare class RequestQueue extends RequestProvider {
|
|
|
74
148
|
* Note that the `null` return value doesn't mean the queue processing finished,
|
|
75
149
|
* it means there are currently no pending requests.
|
|
76
150
|
* To check whether all requests in queue were finished,
|
|
77
|
-
* use {@link RequestQueue.
|
|
151
|
+
* use {@link RequestQueue.checkReadiness} instead.
|
|
78
152
|
*
|
|
79
153
|
* @returns
|
|
80
154
|
* Returns the request object or `null` if there are no more pending requests.
|
|
81
155
|
*/
|
|
82
156
|
fetchNextRequest<T extends Dictionary = Dictionary>(): Promise<Request<T> | null>;
|
|
83
|
-
protected ensureHeadIsNonEmpty(): Promise<void>;
|
|
84
157
|
/**
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* head is consistent.
|
|
90
|
-
* @default false
|
|
91
|
-
* @param [limit] How many queue head items will be fetched.
|
|
92
|
-
* @param [iteration] Used when this function is called recursively to limit the recursion.
|
|
93
|
-
* @returns Indicates if queue head is consistent (true) or inconsistent (false).
|
|
158
|
+
* Marks a request that was previously returned by the
|
|
159
|
+
* {@link RequestQueue.fetchNextRequest}
|
|
160
|
+
* function as handled after successful processing.
|
|
161
|
+
* Handled requests will never again be returned by the `fetchNextRequest` function.
|
|
94
162
|
*/
|
|
95
|
-
|
|
96
|
-
isFinished(): Promise<boolean>;
|
|
163
|
+
markRequestAsHandled(request: Request): Promise<RequestQueueOperationInfo | null>;
|
|
97
164
|
/**
|
|
98
165
|
* Reclaims a failed request back to the queue, so that it can be returned for processing later again
|
|
99
166
|
* by another call to {@link RequestQueue.fetchNextRequest}.
|
|
100
167
|
* The request record in the queue is updated using the provided `request` parameter.
|
|
101
168
|
* For example, this lets you store the number of retries or error messages for the request.
|
|
102
169
|
*/
|
|
103
|
-
reclaimRequest(
|
|
170
|
+
reclaimRequest(request: Request, options?: RequestQueueOperationOptions): Promise<RequestQueueOperationInfo | null>;
|
|
171
|
+
/**
|
|
172
|
+
* A queue hands requests out as fast as they are asked for; pacing is a job for a manager wrapped around it,
|
|
173
|
+
* such as {@link ThrottlingRequestManager}.
|
|
174
|
+
* @inheritdoc
|
|
175
|
+
*/
|
|
176
|
+
recordPacingSignal(_signal: PacingSignal): boolean;
|
|
177
|
+
/**
|
|
178
|
+
* Reports whether the queue has a request to hand over, is waiting on one, or is done.
|
|
179
|
+
*
|
|
180
|
+
* `waiting` means requests are in progress (fetched but not yet handled or reclaimed, possibly by another
|
|
181
|
+
* client sharing the queue) or a background add is still landing; neither has a clock, so no `readyAt`.
|
|
182
|
+
*
|
|
183
|
+
* Due to the nature of distributed storage used by the queue, `finished` may occasionally arrive a probe or
|
|
184
|
+
* two late, but it is never reported early.
|
|
185
|
+
*/
|
|
186
|
+
checkReadiness(): Promise<RequestLoaderStatus>;
|
|
187
|
+
/**
|
|
188
|
+
* Tells the queue how long a consumer expects to hold a fetched request before marking it handled
|
|
189
|
+
* or reclaiming it (typically the request-handler timeout plus padding), so that a storage backend
|
|
190
|
+
* that reserves requests via locking does not hand the same request out again while it is still
|
|
191
|
+
* being processed.
|
|
192
|
+
*
|
|
193
|
+
* Several consumers may share one queue (and therefore one client) in a single process, so we only
|
|
194
|
+
* ever raise the reservation duration, never lower it — otherwise a short-lived consumer could cut
|
|
195
|
+
* short the reservation of a long-lived one and have its in-flight request stolen.
|
|
196
|
+
*/
|
|
197
|
+
setExpectedRequestProcessingTimeSecs(secs: number): Promise<void>;
|
|
198
|
+
/**
|
|
199
|
+
* Caches information about request to beware of unneeded addRequest() calls.
|
|
200
|
+
*/
|
|
201
|
+
private cacheRequest;
|
|
202
|
+
/**
|
|
203
|
+
* Removes the queue either from the Apify Cloud storage or from the local database,
|
|
204
|
+
* depending on the mode of operation.
|
|
205
|
+
*/
|
|
206
|
+
drop(): Promise<void>;
|
|
207
|
+
/**
|
|
208
|
+
* Remove all requests from the queue but keep the queue itself, resetting it
|
|
209
|
+
* so it can be reused (e.g. across multiple `crawler.run()` calls).
|
|
210
|
+
*/
|
|
211
|
+
purge(): Promise<void>;
|
|
104
212
|
/**
|
|
105
213
|
* @inheritdoc
|
|
106
214
|
*/
|
|
107
|
-
|
|
108
|
-
|
|
215
|
+
[Symbol.asyncIterator](): AsyncGenerator<Request<Dictionary>, void, unknown>;
|
|
216
|
+
/**
|
|
217
|
+
* Returns the number of handled requests.
|
|
218
|
+
*
|
|
219
|
+
* This function is just a convenient shortcut for:
|
|
220
|
+
*
|
|
221
|
+
* ```javascript
|
|
222
|
+
* const { handledRequestCount } = await queue.getInfo();
|
|
223
|
+
* ```
|
|
224
|
+
* @inheritdoc
|
|
225
|
+
*/
|
|
226
|
+
getHandledCount(): Promise<number>;
|
|
227
|
+
/**
|
|
228
|
+
* Returns an object containing general information about the request queue.
|
|
229
|
+
*
|
|
230
|
+
* **Example:**
|
|
231
|
+
* ```
|
|
232
|
+
* {
|
|
233
|
+
* id: "WkzbQMuFYuamGv3YF",
|
|
234
|
+
* name: "my-queue",
|
|
235
|
+
* createdAt: new Date("2015-12-12T07:34:14.202Z"),
|
|
236
|
+
* modifiedAt: new Date("2015-12-13T08:36:13.202Z"),
|
|
237
|
+
* accessedAt: new Date("2015-12-14T08:36:13.202Z"),
|
|
238
|
+
* totalRequestCount: 25,
|
|
239
|
+
* handledRequestCount: 5,
|
|
240
|
+
* pendingRequestCount: 20,
|
|
241
|
+
* }
|
|
242
|
+
* ```
|
|
243
|
+
*
|
|
244
|
+
* @throws If the underlying storage no longer exists (e.g. it was deleted externally).
|
|
245
|
+
*/
|
|
246
|
+
getInfo(): Promise<RequestQueueInfo>;
|
|
247
|
+
/**
|
|
248
|
+
* Fetches URLs from requestsFromUrl and returns them in format of list of requests
|
|
249
|
+
*/
|
|
250
|
+
private fetchRequestsFromUrl;
|
|
251
|
+
/**
|
|
252
|
+
* Adds all fetched requests from a URL from a remote resource.
|
|
253
|
+
*/
|
|
254
|
+
private addFetchedRequests;
|
|
255
|
+
/**
|
|
256
|
+
* @internal wraps public utility for mocking purposes
|
|
257
|
+
*/
|
|
258
|
+
private downloadListOfUrls;
|
|
109
259
|
/**
|
|
110
260
|
* Opens a request queue and returns a promise resolving to an instance
|
|
111
261
|
* of the {@link RequestQueue} class.
|
|
@@ -117,12 +267,100 @@ declare class RequestQueue extends RequestProvider {
|
|
|
117
267
|
*
|
|
118
268
|
* For more details and code examples, see the {@link RequestQueue} class.
|
|
119
269
|
*
|
|
120
|
-
* @param [
|
|
121
|
-
* ID or name of the request queue to be opened. If
|
|
122
|
-
*
|
|
270
|
+
* @param [identifier]
|
|
271
|
+
* ID or name of the request queue to be opened. If a string is provided, it will first be
|
|
272
|
+
* looked up as an ID; if no such storage exists, it will be treated as a name.
|
|
273
|
+
* If `null` or `undefined`, the function returns the default request queue associated with the crawler run.
|
|
123
274
|
* @param [options] Open Request Queue options.
|
|
124
275
|
*/
|
|
125
|
-
static open(
|
|
276
|
+
static open(identifier?: string | StorageIdentifier | null, options?: StorageOpenOptions): Promise<RequestQueue>;
|
|
277
|
+
}
|
|
278
|
+
export interface RequestQueueOptions {
|
|
279
|
+
/** Resolved metadata for the request queue, as returned by the backend's `getMetadata()`. */
|
|
280
|
+
metadata: RequestQueueInfo;
|
|
281
|
+
backend: RequestQueueBackend;
|
|
282
|
+
/**
|
|
283
|
+
* Used to pass the proxy configuration for the `requestsFromUrl` objects.
|
|
284
|
+
* Takes advantage of the internal address rotation and authentication process.
|
|
285
|
+
* If undefined, the `requestsFromUrl` requests will be made without proxy.
|
|
286
|
+
*/
|
|
287
|
+
proxyConfiguration?: IProxyConfiguration;
|
|
288
|
+
}
|
|
289
|
+
export interface RequestQueueOperationOptions {
|
|
290
|
+
/**
|
|
291
|
+
* If set to `true`:
|
|
292
|
+
* - while adding the request to the queue: the request will be added to the foremost position in the queue.
|
|
293
|
+
* - while reclaiming the request: the request will be placed to the beginning of the queue, so that it's returned
|
|
294
|
+
* in the next call to {@link RequestQueue.fetchNextRequest}.
|
|
295
|
+
* By default, it's put to the end of the queue.
|
|
296
|
+
*
|
|
297
|
+
* In case the request is already present in the queue, this option has no effect.
|
|
298
|
+
*
|
|
299
|
+
* If more requests are added with this option at once, their order in the following `fetchNextRequest` call
|
|
300
|
+
* is arbitrary.
|
|
301
|
+
* @default false
|
|
302
|
+
*/
|
|
303
|
+
forefront?: boolean;
|
|
304
|
+
/**
|
|
305
|
+
* Should the requests be added to the local LRU cache?
|
|
306
|
+
* @default false
|
|
307
|
+
* @internal
|
|
308
|
+
*/
|
|
309
|
+
cache?: boolean;
|
|
310
|
+
}
|
|
311
|
+
export interface RequestQueueOperationInfo extends QueueOperationInfo {
|
|
312
|
+
uniqueKey: string;
|
|
313
|
+
forefront: boolean;
|
|
314
|
+
}
|
|
315
|
+
export interface AddRequestsBatchedOptions extends RequestQueueOperationOptions {
|
|
316
|
+
/**
|
|
317
|
+
* Whether to wait for all the provided requests to be added, instead of waiting just for the initial batch of up to `batchSize`.
|
|
318
|
+
* @default false
|
|
319
|
+
*/
|
|
320
|
+
waitForAllRequestsToBeAdded?: boolean;
|
|
321
|
+
/**
|
|
322
|
+
* @default 1000
|
|
323
|
+
*/
|
|
324
|
+
batchSize?: number;
|
|
325
|
+
/**
|
|
326
|
+
* @default 1000
|
|
327
|
+
*/
|
|
328
|
+
waitBetweenBatchesMillis?: number;
|
|
329
|
+
/**
|
|
330
|
+
* If set, only this many *actually new* requests (i.e. not already present in the queue) will be added.
|
|
331
|
+
* Once the budget is reached, remaining requests from the iterable will be collected in
|
|
332
|
+
* {@link AddRequestsBatchedResult.requestsOverLimit|`requestsOverLimit`} instead.
|
|
333
|
+
*
|
|
334
|
+
* This is useful in combination with `maxRequestsPerCrawl` to avoid duplicate URLs consuming the budget.
|
|
335
|
+
*
|
|
336
|
+
* **Note:** Setting this option implicitly enables {@link AddRequestsBatchedOptions.waitForAllRequestsToBeAdded|`waitForAllRequestsToBeAdded`},
|
|
337
|
+
* since all batches must complete before leftover requests can be accurately reported.
|
|
338
|
+
*/
|
|
339
|
+
maxNewRequests?: number;
|
|
340
|
+
}
|
|
341
|
+
export interface AddRequestsBatchedResult {
|
|
342
|
+
addedRequests: ProcessedRequest[];
|
|
343
|
+
/**
|
|
344
|
+
* A promise which will resolve with the rest of the requests that were added to the queue.
|
|
345
|
+
*
|
|
346
|
+
* Alternatively, we can set {@link AddRequestsBatchedOptions.waitForAllRequestsToBeAdded|`waitForAllRequestsToBeAdded`} to `true`
|
|
347
|
+
* in the {@link BasicCrawler.addRequests|`crawler.addRequests()`} options.
|
|
348
|
+
*
|
|
349
|
+
* **Example:**
|
|
350
|
+
*
|
|
351
|
+
* ```ts
|
|
352
|
+
* // Assuming `requests` is a list of requests.
|
|
353
|
+
* const result = await crawler.addRequests(requests);
|
|
354
|
+
*
|
|
355
|
+
* // If we want to wait for the rest of the requests to be added to the queue:
|
|
356
|
+
* await result.waitForAllRequestsToBeAdded;
|
|
357
|
+
* ```
|
|
358
|
+
*/
|
|
359
|
+
waitForAllRequestsToBeAdded: Promise<ProcessedRequest[]>;
|
|
360
|
+
/**
|
|
361
|
+
* Requests from the input that were not added to the queue because the
|
|
362
|
+
* {@link AddRequestsBatchedOptions.maxNewRequests|`maxNewRequests`} budget was reached.
|
|
363
|
+
* Empty when `maxNewRequests` is not set.
|
|
364
|
+
*/
|
|
365
|
+
requestsOverLimit?: Source[];
|
|
126
366
|
}
|
|
127
|
-
export { RequestQueue as RequestQueueV1 };
|
|
128
|
-
//# sourceMappingURL=request_queue.d.ts.map
|