@crawlee/core 4.0.0-beta.26 → 4.0.0-beta.261
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 +15 -15
- package/byte-utils.d.ts +17 -0
- package/byte-utils.js +42 -0
- package/configuration.d.ts +77 -235
- package/configuration.js +159 -227
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/errors.d.ts +45 -18
- package/errors.js +58 -27
- package/events/event-manager.d.ts +78 -0
- package/events/{event_manager.js → event-manager.js} +12 -13
- package/events/index.d.ts +3 -3
- package/events/index.js +2 -3
- package/events/local-event-manager.d.ts +32 -0
- package/events/local-event-manager.js +101 -0
- package/events/system-info.d.ts +38 -0
- package/events/system-info.js +1 -0
- package/index.d.ts +9 -12
- package/index.js +10 -11
- package/internal.d.ts +8 -0
- package/internal.js +9 -0
- package/iterables.d.ts +79 -0
- package/iterables.js +134 -0
- package/log.d.ts +77 -1
- package/log.js +134 -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 +43 -0
- package/memory-storage/memory-storage.js +158 -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 +35 -0
- package/memory-storage/resource-clients/dataset.js +108 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +54 -0
- package/memory-storage/resource-clients/key-value-store.js +179 -0
- package/memory-storage/resource-clients/request-queue.d.ts +55 -0
- package/memory-storage/resource-clients/request-queue.js +413 -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 +23 -23
- package/proxy-configuration.d.ts +118 -0
- package/proxy-configuration.js +141 -0
- package/recoverable-state.d.ts +177 -0
- package/recoverable-state.js +268 -0
- package/request.d.ts +48 -93
- package/request.js +139 -232
- package/serialization.d.ts +0 -1
- package/serialization.js +18 -18
- package/service-locator.d.ts +168 -0
- package/service-locator.js +255 -0
- package/storages/batched-adds.d.ts +39 -0
- package/storages/batched-adds.js +78 -0
- package/storages/dataset.d.ts +105 -58
- package/storages/dataset.js +292 -150
- package/storages/index.d.ts +11 -12
- package/storages/index.js +7 -12
- package/storages/key-value-store-codec.d.ts +32 -0
- package/storages/key-value-store-codec.js +108 -0
- package/storages/{key_value_store.d.ts → key-value-store.d.ts} +169 -72
- package/storages/key-value-store.js +767 -0
- package/storages/request-dedup-cache.d.ts +20 -0
- package/storages/request-dedup-cache.js +48 -0
- package/storages/{request_list.d.ts → request-list.d.ts} +33 -173
- package/storages/{request_list.js → request-list.js} +276 -255
- package/storages/request-loader.d.ts +127 -0
- package/storages/request-loader.js +36 -0
- package/storages/request-manager-tandem.d.ts +82 -0
- package/storages/request-manager-tandem.js +200 -0
- package/storages/request-manager.d.ts +119 -0
- package/storages/request-manager.js +1 -0
- package/storages/{request_provider.d.ts → request-queue.d.ts} +128 -159
- package/storages/request-queue.js +871 -0
- package/storages/storage-instance-manager.d.ts +86 -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/transaction.d.ts +270 -0
- package/storages/transaction.js +296 -0
- package/storages/utils.d.ts +59 -11
- package/storages/utils.js +76 -16
- 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 +23 -18
- package/validators.js +14 -18
- package/autoscaling/autoscaled_pool.d.ts +0 -300
- package/autoscaling/autoscaled_pool.d.ts.map +0 -1
- package/autoscaling/autoscaled_pool.js +0 -533
- package/autoscaling/autoscaled_pool.js.map +0 -1
- package/autoscaling/index.d.ts +0 -4
- package/autoscaling/index.d.ts.map +0 -1
- package/autoscaling/index.js +0 -4
- package/autoscaling/index.js.map +0 -1
- package/autoscaling/snapshotter.d.ts +0 -189
- package/autoscaling/snapshotter.d.ts.map +0 -1
- package/autoscaling/snapshotter.js +0 -285
- package/autoscaling/snapshotter.js.map +0 -1
- package/autoscaling/system_status.d.ts +0 -181
- package/autoscaling/system_status.d.ts.map +0 -1
- package/autoscaling/system_status.js +0 -169
- 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 +0 -43
- package/cookie_utils.d.ts.map +0 -1
- package/cookie_utils.js +0 -111
- package/cookie_utils.js.map +0 -1
- package/crawlers/context_pipeline.d.ts +0 -61
- package/crawlers/context_pipeline.d.ts.map +0 -1
- package/crawlers/context_pipeline.js +0 -99
- package/crawlers/context_pipeline.js.map +0 -1
- package/crawlers/crawler_commons.d.ts +0 -191
- package/crawlers/crawler_commons.d.ts.map +0 -1
- package/crawlers/crawler_commons.js +0 -108
- 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 +0 -60
- package/crawlers/error_snapshotter.d.ts.map +0 -1
- package/crawlers/error_snapshotter.js +0 -118
- package/crawlers/error_snapshotter.js.map +0 -1
- package/crawlers/error_tracker.d.ts +0 -55
- package/crawlers/error_tracker.d.ts.map +0 -1
- package/crawlers/error_tracker.js +0 -309
- package/crawlers/error_tracker.js.map +0 -1
- package/crawlers/index.d.ts +0 -7
- package/crawlers/index.d.ts.map +0 -1
- package/crawlers/index.js +0 -7
- package/crawlers/index.js.map +0 -1
- package/crawlers/internals/types.d.ts +0 -8
- package/crawlers/internals/types.d.ts.map +0 -1
- package/crawlers/internals/types.js +0 -2
- package/crawlers/internals/types.js.map +0 -1
- package/crawlers/statistics.d.ts +0 -213
- package/crawlers/statistics.d.ts.map +0 -1
- package/crawlers/statistics.js +0 -349
- package/crawlers/statistics.js.map +0 -1
- package/enqueue_links/enqueue_links.d.ts +0 -249
- package/enqueue_links/enqueue_links.d.ts.map +0 -1
- package/enqueue_links/enqueue_links.js +0 -269
- package/enqueue_links/enqueue_links.js.map +0 -1
- package/enqueue_links/index.d.ts +0 -3
- package/enqueue_links/index.d.ts.map +0 -1
- package/enqueue_links/index.js +0 -3
- package/enqueue_links/index.js.map +0 -1
- package/enqueue_links/shared.d.ts +0 -73
- package/enqueue_links/shared.d.ts.map +0 -1
- package/enqueue_links/shared.js +0 -212
- 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 +0 -52
- 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 +0 -27
- package/events/local_event_manager.d.ts.map +0 -1
- package/events/local_event_manager.js +0 -75
- package/events/local_event_manager.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 +0 -169
- package/proxy_configuration.d.ts.map +0 -1
- package/proxy_configuration.js +0 -247
- package/proxy_configuration.js.map +0 -1
- package/recoverable_state.d.ts +0 -123
- package/recoverable_state.d.ts.map +0 -1
- package/recoverable_state.js +0 -140
- package/recoverable_state.js.map +0 -1
- package/request.d.ts.map +0 -1
- package/request.js.map +0 -1
- package/router.d.ts +0 -134
- package/router.d.ts.map +0 -1
- package/router.js +0 -164
- 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 +0 -4
- package/session_pool/consts.d.ts.map +0 -1
- package/session_pool/consts.js +0 -4
- package/session_pool/consts.js.map +0 -1
- package/session_pool/errors.d.ts +0 -8
- package/session_pool/errors.d.ts.map +0 -1
- package/session_pool/errors.js +0 -12
- 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 +0 -6
- package/session_pool/index.d.ts.map +0 -1
- package/session_pool/index.js +0 -6
- package/session_pool/index.js.map +0 -1
- package/session_pool/session.d.ts +0 -186
- package/session_pool/session.d.ts.map +0 -1
- package/session_pool/session.js +0 -278
- package/session_pool/session.js.map +0 -1
- package/session_pool/session_pool.d.ts +0 -258
- package/session_pool/session_pool.d.ts.map +0 -1
- package/session_pool/session_pool.js +0 -387
- 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 +0 -512
- 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 +0 -68
- package/storages/request_manager_tandem.d.ts.map +0 -1
- package/storages/request_manager_tandem.js +0 -124
- package/storages/request_manager_tandem.js.map +0 -1
- package/storages/request_provider.d.ts.map +0 -1
- package/storages/request_provider.js +0 -591
- package/storages/request_provider.js.map +0 -1
- package/storages/request_queue.d.ts +0 -128
- package/storages/request_queue.d.ts.map +0 -1
- package/storages/request_queue.js +0 -320
- 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 +0 -250
- package/storages/sitemap_request_list.d.ts.map +0 -1
- package/storages/sitemap_request_list.js +0 -431
- package/storages/sitemap_request_list.js.map +0 -1
- package/storages/storage_manager.d.ts +0 -62
- 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,128 +0,0 @@
|
|
|
1
|
-
import type { Dictionary } from '@crawlee/types';
|
|
2
|
-
import { Configuration } from '../configuration.js';
|
|
3
|
-
import type { Request } from '../request.js';
|
|
4
|
-
import type { RequestProviderOptions, RequestQueueOperationInfo } from './request_provider.js';
|
|
5
|
-
import { RequestProvider } from './request_provider.js';
|
|
6
|
-
/**
|
|
7
|
-
* Represents a queue of URLs to crawl, which is used for deep crawling of websites
|
|
8
|
-
* where you start with several URLs and then recursively
|
|
9
|
-
* follow links to other pages. The data structure supports both breadth-first and depth-first crawling orders.
|
|
10
|
-
*
|
|
11
|
-
* Each URL is represented using an instance of the {@link Request} class.
|
|
12
|
-
* The queue can only contain unique URLs. More precisely, it can only contain {@link Request} instances
|
|
13
|
-
* with distinct `uniqueKey` properties. By default, `uniqueKey` is generated from the URL, but it can also be overridden.
|
|
14
|
-
* To add a single URL multiple times to the queue,
|
|
15
|
-
* corresponding {@link Request} objects will need to have different `uniqueKey` properties.
|
|
16
|
-
*
|
|
17
|
-
* Do not instantiate this class directly, use the {@link RequestQueue.open} function instead.
|
|
18
|
-
*
|
|
19
|
-
* `RequestQueue` is used by {@link BasicCrawler}, {@link CheerioCrawler}, {@link PuppeteerCrawler}
|
|
20
|
-
* and {@link PlaywrightCrawler} as a source of URLs to crawl.
|
|
21
|
-
* Unlike {@link RequestList}, `RequestQueue` supports dynamic adding and removing of requests.
|
|
22
|
-
* On the other hand, the queue is not optimized for operations that add or remove a large number of URLs in a batch.
|
|
23
|
-
*
|
|
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
|
-
* **Example usage:**
|
|
37
|
-
*
|
|
38
|
-
* ```javascript
|
|
39
|
-
* // Open the default request queue associated with the crawler run
|
|
40
|
-
* const queue = await RequestQueue.open();
|
|
41
|
-
*
|
|
42
|
-
* // Open a named request queue
|
|
43
|
-
* const queueWithName = await RequestQueue.open('some-name');
|
|
44
|
-
*
|
|
45
|
-
* // Enqueue few requests
|
|
46
|
-
* await queue.addRequest({ url: 'http://example.com/aaa' });
|
|
47
|
-
* await queue.addRequest({ url: 'http://example.com/bbb' });
|
|
48
|
-
* await queue.addRequest({ url: 'http://example.com/foo/bar' }, { forefront: true });
|
|
49
|
-
* ```
|
|
50
|
-
* @category Sources
|
|
51
|
-
*
|
|
52
|
-
* @deprecated RequestQueue v1 is deprecated and will be removed in the future. Please use {@link RequestQueue} instead.
|
|
53
|
-
*/
|
|
54
|
-
declare class RequestQueue extends RequestProvider {
|
|
55
|
-
private queryQueueHeadPromise?;
|
|
56
|
-
private inProgress;
|
|
57
|
-
/**
|
|
58
|
-
* @internal
|
|
59
|
-
*/
|
|
60
|
-
constructor(options: RequestProviderOptions, config?: Configuration);
|
|
61
|
-
/**
|
|
62
|
-
* @internal
|
|
63
|
-
*/
|
|
64
|
-
inProgressCount(): number;
|
|
65
|
-
/**
|
|
66
|
-
* Returns a next request in the queue to be processed, or `null` if there are no more pending requests.
|
|
67
|
-
*
|
|
68
|
-
* Once you successfully finish processing of the request, you need to call
|
|
69
|
-
* {@link RequestQueue.markRequestHandled}
|
|
70
|
-
* to mark the request as handled in the queue. If there was some error in processing the request,
|
|
71
|
-
* call {@link RequestQueue.reclaimRequest} instead,
|
|
72
|
-
* so that the queue will give the request to some other consumer in another call to the `fetchNextRequest` function.
|
|
73
|
-
*
|
|
74
|
-
* Note that the `null` return value doesn't mean the queue processing finished,
|
|
75
|
-
* it means there are currently no pending requests.
|
|
76
|
-
* To check whether all requests in queue were finished,
|
|
77
|
-
* use {@link RequestQueue.isFinished} instead.
|
|
78
|
-
*
|
|
79
|
-
* @returns
|
|
80
|
-
* Returns the request object or `null` if there are no more pending requests.
|
|
81
|
-
*/
|
|
82
|
-
fetchNextRequest<T extends Dictionary = Dictionary>(): Promise<Request<T> | null>;
|
|
83
|
-
protected ensureHeadIsNonEmpty(): Promise<void>;
|
|
84
|
-
/**
|
|
85
|
-
* We always request more items than is in progress to ensure that something falls into head.
|
|
86
|
-
*
|
|
87
|
-
* @param [ensureConsistency] If true then query for queue head is retried until queueModifiedAt
|
|
88
|
-
* is older than queryStartedAt by at least API_PROCESSED_REQUESTS_DELAY_MILLIS to ensure that queue
|
|
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).
|
|
94
|
-
*/
|
|
95
|
-
protected _ensureHeadIsNonEmpty(ensureConsistency?: boolean, limit?: number, iteration?: number): Promise<boolean>;
|
|
96
|
-
isFinished(): Promise<boolean>;
|
|
97
|
-
/**
|
|
98
|
-
* Reclaims a failed request back to the queue, so that it can be returned for processing later again
|
|
99
|
-
* by another call to {@link RequestQueue.fetchNextRequest}.
|
|
100
|
-
* The request record in the queue is updated using the provided `request` parameter.
|
|
101
|
-
* For example, this lets you store the number of retries or error messages for the request.
|
|
102
|
-
*/
|
|
103
|
-
reclaimRequest(...args: Parameters<RequestProvider['reclaimRequest']>): Promise<RequestQueueOperationInfo | null>;
|
|
104
|
-
/**
|
|
105
|
-
* @inheritdoc
|
|
106
|
-
*/
|
|
107
|
-
markRequestHandled(request: Request): Promise<RequestQueueOperationInfo | null>;
|
|
108
|
-
protected _reset(): void;
|
|
109
|
-
/**
|
|
110
|
-
* Opens a request queue and returns a promise resolving to an instance
|
|
111
|
-
* of the {@link RequestQueue} class.
|
|
112
|
-
*
|
|
113
|
-
* {@link RequestQueue} represents a queue of URLs to crawl, which is stored either on local filesystem or in the cloud.
|
|
114
|
-
* The queue is used for deep crawling of websites, where you start with several URLs and then
|
|
115
|
-
* recursively follow links to other pages. The data structure supports both breadth-first
|
|
116
|
-
* and depth-first crawling orders.
|
|
117
|
-
*
|
|
118
|
-
* For more details and code examples, see the {@link RequestQueue} class.
|
|
119
|
-
*
|
|
120
|
-
* @param [queueIdOrName]
|
|
121
|
-
* ID or name of the request queue to be opened. If `null` or `undefined`,
|
|
122
|
-
* the function returns the default request queue associated with the crawler run.
|
|
123
|
-
* @param [options] Open Request Queue options.
|
|
124
|
-
*/
|
|
125
|
-
static open(...args: Parameters<typeof RequestProvider.open>): Promise<RequestQueue>;
|
|
126
|
-
}
|
|
127
|
-
export { RequestQueue as RequestQueueV1 };
|
|
128
|
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B,GAAG,IAAI,CAAC;cAQ3E,MAAM,IAAI,IAAI;IAMjC;;;;;;;;;;;;;;;OAeG;WACmB,IAAI,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,OAAO,eAAe,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,YAAY,CAAC;CAGtG;AAED,OAAO,EAAE,YAAY,IAAI,cAAc,EAAE,CAAC"}
|
|
@@ -1,320 +0,0 @@
|
|
|
1
|
-
import { setTimeout as sleep } from 'node:timers/promises';
|
|
2
|
-
import { REQUEST_QUEUE_HEAD_MAX_LIMIT } from '@apify/consts';
|
|
3
|
-
import { Configuration } from '../configuration.js';
|
|
4
|
-
import { checkStorageAccess } from './access_checking.js';
|
|
5
|
-
import { RequestProvider } from './request_provider.js';
|
|
6
|
-
import { API_PROCESSED_REQUESTS_DELAY_MILLIS, getRequestId, MAX_QUERIES_FOR_CONSISTENCY, QUERY_HEAD_BUFFER, QUERY_HEAD_MIN_LENGTH, STORAGE_CONSISTENCY_DELAY_MILLIS, } from './utils.js';
|
|
7
|
-
const MAX_CACHED_REQUESTS = 1_000_000;
|
|
8
|
-
/**
|
|
9
|
-
* This number must be large enough so that processing of all these requests cannot be done in
|
|
10
|
-
* a time lower than expected maximum latency of DynamoDB, but low enough not to waste too much memory.
|
|
11
|
-
* @internal
|
|
12
|
-
*/
|
|
13
|
-
const RECENTLY_HANDLED_CACHE_SIZE = 1000;
|
|
14
|
-
/**
|
|
15
|
-
* Represents a queue of URLs to crawl, which is used for deep crawling of websites
|
|
16
|
-
* where you start with several URLs and then recursively
|
|
17
|
-
* follow links to other pages. The data structure supports both breadth-first and depth-first crawling orders.
|
|
18
|
-
*
|
|
19
|
-
* Each URL is represented using an instance of the {@link Request} class.
|
|
20
|
-
* The queue can only contain unique URLs. More precisely, it can only contain {@link Request} instances
|
|
21
|
-
* with distinct `uniqueKey` properties. By default, `uniqueKey` is generated from the URL, but it can also be overridden.
|
|
22
|
-
* To add a single URL multiple times to the queue,
|
|
23
|
-
* corresponding {@link Request} objects will need to have different `uniqueKey` properties.
|
|
24
|
-
*
|
|
25
|
-
* Do not instantiate this class directly, use the {@link RequestQueue.open} function instead.
|
|
26
|
-
*
|
|
27
|
-
* `RequestQueue` is used by {@link BasicCrawler}, {@link CheerioCrawler}, {@link PuppeteerCrawler}
|
|
28
|
-
* and {@link PlaywrightCrawler} as a source of URLs to crawl.
|
|
29
|
-
* Unlike {@link RequestList}, `RequestQueue` supports dynamic adding and removing of requests.
|
|
30
|
-
* On the other hand, the queue is not optimized for operations that add or remove a large number of URLs in a batch.
|
|
31
|
-
*
|
|
32
|
-
* `RequestQueue` stores its data either on local disk or in the Apify Cloud,
|
|
33
|
-
* depending on whether the `APIFY_LOCAL_STORAGE_DIR` or `APIFY_TOKEN` environment variable is set.
|
|
34
|
-
*
|
|
35
|
-
* If the `APIFY_LOCAL_STORAGE_DIR` environment variable is set, the queue data is stored in
|
|
36
|
-
* that directory in an SQLite database file.
|
|
37
|
-
*
|
|
38
|
-
* If the `APIFY_TOKEN` environment variable is set but `APIFY_LOCAL_STORAGE_DIR` is not, the data is stored in the
|
|
39
|
-
* [Apify Request Queue](https://docs.apify.com/storage/request-queue)
|
|
40
|
-
* cloud storage. Note that you can force usage of the cloud storage also by passing the `forceCloud`
|
|
41
|
-
* option to {@link RequestQueue.open} function,
|
|
42
|
-
* even if the `APIFY_LOCAL_STORAGE_DIR` variable is set.
|
|
43
|
-
*
|
|
44
|
-
* **Example usage:**
|
|
45
|
-
*
|
|
46
|
-
* ```javascript
|
|
47
|
-
* // Open the default request queue associated with the crawler run
|
|
48
|
-
* const queue = await RequestQueue.open();
|
|
49
|
-
*
|
|
50
|
-
* // Open a named request queue
|
|
51
|
-
* const queueWithName = await RequestQueue.open('some-name');
|
|
52
|
-
*
|
|
53
|
-
* // Enqueue few requests
|
|
54
|
-
* await queue.addRequest({ url: 'http://example.com/aaa' });
|
|
55
|
-
* await queue.addRequest({ url: 'http://example.com/bbb' });
|
|
56
|
-
* await queue.addRequest({ url: 'http://example.com/foo/bar' }, { forefront: true });
|
|
57
|
-
* ```
|
|
58
|
-
* @category Sources
|
|
59
|
-
*
|
|
60
|
-
* @deprecated RequestQueue v1 is deprecated and will be removed in the future. Please use {@link RequestQueue} instead.
|
|
61
|
-
*/
|
|
62
|
-
class RequestQueue extends RequestProvider {
|
|
63
|
-
queryQueueHeadPromise = null;
|
|
64
|
-
inProgress = new Set();
|
|
65
|
-
/**
|
|
66
|
-
* @internal
|
|
67
|
-
*/
|
|
68
|
-
constructor(options, config = Configuration.getGlobalConfig()) {
|
|
69
|
-
super({
|
|
70
|
-
...options,
|
|
71
|
-
logPrefix: 'RequestQueue',
|
|
72
|
-
recentlyHandledRequestsMaxSize: RECENTLY_HANDLED_CACHE_SIZE,
|
|
73
|
-
requestCacheMaxSize: MAX_CACHED_REQUESTS,
|
|
74
|
-
}, config);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* @internal
|
|
78
|
-
*/
|
|
79
|
-
inProgressCount() {
|
|
80
|
-
return this.inProgress.size;
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* Returns a next request in the queue to be processed, or `null` if there are no more pending requests.
|
|
84
|
-
*
|
|
85
|
-
* Once you successfully finish processing of the request, you need to call
|
|
86
|
-
* {@link RequestQueue.markRequestHandled}
|
|
87
|
-
* to mark the request as handled in the queue. If there was some error in processing the request,
|
|
88
|
-
* call {@link RequestQueue.reclaimRequest} instead,
|
|
89
|
-
* so that the queue will give the request to some other consumer in another call to the `fetchNextRequest` function.
|
|
90
|
-
*
|
|
91
|
-
* Note that the `null` return value doesn't mean the queue processing finished,
|
|
92
|
-
* it means there are currently no pending requests.
|
|
93
|
-
* To check whether all requests in queue were finished,
|
|
94
|
-
* use {@link RequestQueue.isFinished} instead.
|
|
95
|
-
*
|
|
96
|
-
* @returns
|
|
97
|
-
* Returns the request object or `null` if there are no more pending requests.
|
|
98
|
-
*/
|
|
99
|
-
async fetchNextRequest() {
|
|
100
|
-
checkStorageAccess();
|
|
101
|
-
this.lastActivity = new Date();
|
|
102
|
-
await this.ensureHeadIsNonEmpty();
|
|
103
|
-
const nextRequestId = this.queueHeadIds.removeFirst();
|
|
104
|
-
// We are likely done at this point.
|
|
105
|
-
if (!nextRequestId)
|
|
106
|
-
return null;
|
|
107
|
-
// This should never happen, but...
|
|
108
|
-
if (this.inProgress.has(nextRequestId) || this.recentlyHandledRequestsCache.get(nextRequestId)) {
|
|
109
|
-
this.log.warning('Queue head returned a request that is already in progress?!', {
|
|
110
|
-
nextRequestId,
|
|
111
|
-
inProgress: this.inProgress.has(nextRequestId),
|
|
112
|
-
recentlyHandled: !!this.recentlyHandledRequestsCache.get(nextRequestId),
|
|
113
|
-
});
|
|
114
|
-
return null;
|
|
115
|
-
}
|
|
116
|
-
this.inProgress.add(nextRequestId);
|
|
117
|
-
this.lastActivity = new Date();
|
|
118
|
-
let request;
|
|
119
|
-
try {
|
|
120
|
-
request = await this.getRequest(nextRequestId);
|
|
121
|
-
}
|
|
122
|
-
catch (e) {
|
|
123
|
-
// On error, remove the request from in progress, otherwise it would be there forever
|
|
124
|
-
this.inProgress.delete(nextRequestId);
|
|
125
|
-
throw e;
|
|
126
|
-
}
|
|
127
|
-
// NOTE: It can happen that the queue head index is inconsistent with the main queue table. This can occur in two situations:
|
|
128
|
-
// 1) Queue head index is ahead of the main table and the request is not present in the main table yet (i.e. getRequest() returned null).
|
|
129
|
-
// In this case, keep the request marked as in progress for a short while,
|
|
130
|
-
// so that isFinished() doesn't return true and _ensureHeadIsNonEmpty() doesn't not load the request
|
|
131
|
-
// into the queueHeadDict straight again. After the interval expires, fetchNextRequest()
|
|
132
|
-
// will try to fetch this request again, until it eventually appears in the main table.
|
|
133
|
-
if (!request) {
|
|
134
|
-
this.log.debug('Cannot find a request from the beginning of queue, will be retried later', {
|
|
135
|
-
nextRequestId,
|
|
136
|
-
});
|
|
137
|
-
setTimeout(() => {
|
|
138
|
-
this.inProgress.delete(nextRequestId);
|
|
139
|
-
}, STORAGE_CONSISTENCY_DELAY_MILLIS);
|
|
140
|
-
return null;
|
|
141
|
-
}
|
|
142
|
-
// 2) Queue head index is behind the main table and the underlying request was already handled
|
|
143
|
-
// (by some other client, since we keep the track of handled requests in recentlyHandled dictionary).
|
|
144
|
-
// We just add the request to the recentlyHandled dictionary so that next call to _ensureHeadIsNonEmpty()
|
|
145
|
-
// will not put the request again to queueHeadDict.
|
|
146
|
-
if (request.handledAt) {
|
|
147
|
-
this.log.debug('Request fetched from the beginning of queue was already handled', { nextRequestId });
|
|
148
|
-
this.recentlyHandledRequestsCache.add(nextRequestId, true);
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
return request;
|
|
152
|
-
}
|
|
153
|
-
async ensureHeadIsNonEmpty() {
|
|
154
|
-
// Alias for backwards compatibility
|
|
155
|
-
await this._ensureHeadIsNonEmpty();
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* We always request more items than is in progress to ensure that something falls into head.
|
|
159
|
-
*
|
|
160
|
-
* @param [ensureConsistency] If true then query for queue head is retried until queueModifiedAt
|
|
161
|
-
* is older than queryStartedAt by at least API_PROCESSED_REQUESTS_DELAY_MILLIS to ensure that queue
|
|
162
|
-
* head is consistent.
|
|
163
|
-
* @default false
|
|
164
|
-
* @param [limit] How many queue head items will be fetched.
|
|
165
|
-
* @param [iteration] Used when this function is called recursively to limit the recursion.
|
|
166
|
-
* @returns Indicates if queue head is consistent (true) or inconsistent (false).
|
|
167
|
-
*/
|
|
168
|
-
async _ensureHeadIsNonEmpty(ensureConsistency = false, limit = Math.max(this.inProgressCount() * QUERY_HEAD_BUFFER, QUERY_HEAD_MIN_LENGTH), iteration = 0) {
|
|
169
|
-
// If we are paused for migration, resolve immediately.
|
|
170
|
-
if (this.queuePausedForMigration) {
|
|
171
|
-
return true;
|
|
172
|
-
}
|
|
173
|
-
// If is nonempty resolve immediately.
|
|
174
|
-
if (this.queueHeadIds.length() > 0) {
|
|
175
|
-
return true;
|
|
176
|
-
}
|
|
177
|
-
if (!this.queryQueueHeadPromise) {
|
|
178
|
-
const queryStartedAt = new Date();
|
|
179
|
-
this.queryQueueHeadPromise = this.client
|
|
180
|
-
.listHead({ limit })
|
|
181
|
-
.then(({ items, queueModifiedAt, hadMultipleClients }) => {
|
|
182
|
-
items.forEach(({ id: requestId, uniqueKey }) => {
|
|
183
|
-
// Queue head index might be behind the main table, so ensure we don't recycle requests
|
|
184
|
-
if (!requestId ||
|
|
185
|
-
!uniqueKey ||
|
|
186
|
-
this.inProgress.has(requestId) ||
|
|
187
|
-
this.recentlyHandledRequestsCache.get(requestId))
|
|
188
|
-
return;
|
|
189
|
-
this.queueHeadIds.add(requestId, requestId, false);
|
|
190
|
-
const forefront = this.requestCache.get(getRequestId(uniqueKey))?.forefront ?? false;
|
|
191
|
-
this._cacheRequest(getRequestId(uniqueKey), {
|
|
192
|
-
requestId,
|
|
193
|
-
wasAlreadyHandled: false,
|
|
194
|
-
wasAlreadyPresent: true,
|
|
195
|
-
uniqueKey,
|
|
196
|
-
forefront,
|
|
197
|
-
});
|
|
198
|
-
});
|
|
199
|
-
// This is needed so that the next call to _ensureHeadIsNonEmpty() will fetch the queue head again.
|
|
200
|
-
this.queryQueueHeadPromise = null;
|
|
201
|
-
return {
|
|
202
|
-
wasLimitReached: items.length >= limit,
|
|
203
|
-
prevLimit: limit,
|
|
204
|
-
queueModifiedAt: new Date(queueModifiedAt),
|
|
205
|
-
queryStartedAt,
|
|
206
|
-
hadMultipleClients,
|
|
207
|
-
};
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
const { queueModifiedAt, wasLimitReached, prevLimit, queryStartedAt, hadMultipleClients } = await this.queryQueueHeadPromise;
|
|
211
|
-
// TODO: I feel this code below can be greatly simplified...
|
|
212
|
-
// If queue is still empty then one of the following holds:
|
|
213
|
-
// - the other calls waiting for this promise already consumed all the returned requests
|
|
214
|
-
// - the limit was too low and contained only requests in progress
|
|
215
|
-
// - the writes from other clients were not propagated yet
|
|
216
|
-
// - the whole queue was processed and we are done
|
|
217
|
-
// If limit was not reached in the call then there are no more requests to be returned.
|
|
218
|
-
if (prevLimit >= REQUEST_QUEUE_HEAD_MAX_LIMIT) {
|
|
219
|
-
this.log.warning(`Reached the maximum number of requests in progress: ${REQUEST_QUEUE_HEAD_MAX_LIMIT}.`);
|
|
220
|
-
}
|
|
221
|
-
const shouldRepeatWithHigherLimit = this.queueHeadIds.length() === 0 && wasLimitReached && prevLimit < REQUEST_QUEUE_HEAD_MAX_LIMIT;
|
|
222
|
-
// If ensureConsistency=true then we must ensure that either:
|
|
223
|
-
// - queueModifiedAt is older than queryStartedAt by at least API_PROCESSED_REQUESTS_DELAY_MILLIS
|
|
224
|
-
// - hadMultipleClients=false and this.assumedTotalCount<=this.assumedHandledCount
|
|
225
|
-
const isDatabaseConsistent = +queryStartedAt - +queueModifiedAt >= API_PROCESSED_REQUESTS_DELAY_MILLIS;
|
|
226
|
-
const isLocallyConsistent = !hadMultipleClients && this.assumedTotalCount <= this.assumedHandledCount;
|
|
227
|
-
// Consistent information from one source is enough to consider request queue finished.
|
|
228
|
-
const shouldRepeatForConsistency = ensureConsistency && !isDatabaseConsistent && !isLocallyConsistent;
|
|
229
|
-
// If both are false then head is consistent and we may exit.
|
|
230
|
-
if (!shouldRepeatWithHigherLimit && !shouldRepeatForConsistency)
|
|
231
|
-
return true;
|
|
232
|
-
// If we are querying for consistency then we limit the number of queries to MAX_QUERIES_FOR_CONSISTENCY.
|
|
233
|
-
// If this is reached then we return false so that empty() and finished() returns possibly false negative.
|
|
234
|
-
if (!shouldRepeatWithHigherLimit && iteration > MAX_QUERIES_FOR_CONSISTENCY)
|
|
235
|
-
return false;
|
|
236
|
-
const nextLimit = shouldRepeatWithHigherLimit ? Math.round(prevLimit * 1.5) : prevLimit;
|
|
237
|
-
// If we are repeating for consistency then wait required time.
|
|
238
|
-
if (shouldRepeatForConsistency) {
|
|
239
|
-
const delayMillis = API_PROCESSED_REQUESTS_DELAY_MILLIS - (Date.now() - +queueModifiedAt);
|
|
240
|
-
this.log.info(`Waiting for ${delayMillis}ms before considering the queue as finished to ensure that the data is consistent.`);
|
|
241
|
-
await sleep(delayMillis);
|
|
242
|
-
}
|
|
243
|
-
return this._ensureHeadIsNonEmpty(ensureConsistency, nextLimit, iteration + 1);
|
|
244
|
-
}
|
|
245
|
-
// RequestQueue v1 behavior overrides below
|
|
246
|
-
async isFinished() {
|
|
247
|
-
checkStorageAccess();
|
|
248
|
-
if (Date.now() - +this.lastActivity > this.internalTimeoutMillis) {
|
|
249
|
-
const message = `The request queue seems to be stuck for ${this.internalTimeoutMillis / 1e3}s, resetting internal state.`;
|
|
250
|
-
this.log.warning(message, { inProgress: [...this.inProgress] });
|
|
251
|
-
this._reset();
|
|
252
|
-
}
|
|
253
|
-
if (this.inProgressRequestBatchCount > 0) {
|
|
254
|
-
return false;
|
|
255
|
-
}
|
|
256
|
-
if (this.queueHeadIds.length() > 0 || this.inProgressCount() > 0)
|
|
257
|
-
return false;
|
|
258
|
-
const isHeadConsistent = await this._ensureHeadIsNonEmpty(true);
|
|
259
|
-
return isHeadConsistent && this.queueHeadIds.length() === 0 && this.inProgressCount() === 0;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Reclaims a failed request back to the queue, so that it can be returned for processing later again
|
|
263
|
-
* by another call to {@link RequestQueue.fetchNextRequest}.
|
|
264
|
-
* The request record in the queue is updated using the provided `request` parameter.
|
|
265
|
-
* For example, this lets you store the number of retries or error messages for the request.
|
|
266
|
-
*/
|
|
267
|
-
async reclaimRequest(...args) {
|
|
268
|
-
checkStorageAccess();
|
|
269
|
-
const [request, options] = args;
|
|
270
|
-
const forefront = options?.forefront ?? false;
|
|
271
|
-
const result = await super.reclaimRequest(...args);
|
|
272
|
-
// Wait a little to increase a chance that the next call to fetchNextRequest() will return the request with updated data.
|
|
273
|
-
// This is to compensate for the limitation of DynamoDB, where writes might not be immediately visible to subsequent reads.
|
|
274
|
-
setTimeout(() => {
|
|
275
|
-
if (!this.inProgress.has(request.id)) {
|
|
276
|
-
this.log.debug('The request is no longer marked as in progress in the queue?!', {
|
|
277
|
-
requestId: request.id,
|
|
278
|
-
});
|
|
279
|
-
return;
|
|
280
|
-
}
|
|
281
|
-
this.inProgress.delete(request.id);
|
|
282
|
-
// Performance optimization: add request straight to head if possible
|
|
283
|
-
this._maybeAddRequestToQueueHead(request.id, forefront);
|
|
284
|
-
}, STORAGE_CONSISTENCY_DELAY_MILLIS);
|
|
285
|
-
return result;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* @inheritdoc
|
|
289
|
-
*/
|
|
290
|
-
async markRequestHandled(request) {
|
|
291
|
-
const res = await super.markRequestHandled(request);
|
|
292
|
-
this.inProgress.delete(request.id);
|
|
293
|
-
return res;
|
|
294
|
-
}
|
|
295
|
-
_reset() {
|
|
296
|
-
super._reset();
|
|
297
|
-
this.inProgress.clear();
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* Opens a request queue and returns a promise resolving to an instance
|
|
301
|
-
* of the {@link RequestQueue} class.
|
|
302
|
-
*
|
|
303
|
-
* {@link RequestQueue} represents a queue of URLs to crawl, which is stored either on local filesystem or in the cloud.
|
|
304
|
-
* The queue is used for deep crawling of websites, where you start with several URLs and then
|
|
305
|
-
* recursively follow links to other pages. The data structure supports both breadth-first
|
|
306
|
-
* and depth-first crawling orders.
|
|
307
|
-
*
|
|
308
|
-
* For more details and code examples, see the {@link RequestQueue} class.
|
|
309
|
-
*
|
|
310
|
-
* @param [queueIdOrName]
|
|
311
|
-
* ID or name of the request queue to be opened. If `null` or `undefined`,
|
|
312
|
-
* the function returns the default request queue associated with the crawler run.
|
|
313
|
-
* @param [options] Open Request Queue options.
|
|
314
|
-
*/
|
|
315
|
-
static async open(...args) {
|
|
316
|
-
return super.open(...args);
|
|
317
|
-
}
|
|
318
|
-
}
|
|
319
|
-
export { RequestQueue as RequestQueueV1 };
|
|
320
|
-
//# sourceMappingURL=request_queue.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request_queue.js","sourceRoot":"","sources":["../../src/storages/request_queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,KAAK,EAAE,MAAM,sBAAsB,CAAC;AAI3D,OAAO,EAAE,4BAA4B,EAAE,MAAM,eAAe,CAAC;AAE7D,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EACH,mCAAmC,EACnC,YAAY,EACZ,2BAA2B,EAC3B,iBAAiB,EACjB,qBAAqB,EACrB,gCAAgC,GACnC,MAAM,YAAY,CAAC;AAEpB,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAEtC;;;;GAIG;AACH,MAAM,2BAA2B,GAAG,IAAI,CAAC;AAEzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,MAAM,YAAa,SAAQ,eAAe;IAC9B,qBAAqB,GAMjB,IAAI,CAAC;IAET,UAAU,GAAG,IAAI,GAAG,EAAU,CAAC;IAEvC;;OAEG;IACH,YAAY,OAA+B,EAAE,MAAM,GAAG,aAAa,CAAC,eAAe,EAAE;QACjF,KAAK,CACD;YACI,GAAG,OAAO;YACV,SAAS,EAAE,cAAc;YACzB,8BAA8B,EAAE,2BAA2B;YAC3D,mBAAmB,EAAE,mBAAmB;SAC3C,EACD,MAAM,CACT,CAAC;IACN,CAAC;IAED;;OAEG;IACI,eAAe;QAClB,OAAO,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;IAChC,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACM,KAAK,CAAC,gBAAgB;QAC3B,kBAAkB,EAAE,CAAC;QAErB,IAAI,CAAC,YAAY,GAAG,IAAI,IAAI,EAAE,CAAC;Q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C,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,EAAG,CAAC,EAAE,CAAC;gBACpC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,+DAA+D,EAAE;oBAC5E,SAAS,EAAE,OAAO,CAAC,EAAE;iBACxB,CAAC,CAAC;gBACH,OAAO;YACX,CAAC;YAED,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,EAAG,CAAC,CAAC;YAEpC,qEAAqE;YACrE,IAAI,CAAC,2BAA2B,CAAC,OAAO,CAAC,EAAG,EAAE,SAAS,CAAC,CAAC;QAC7D,CAAC,EAAE,gCAAgC,CAAC,CAAC;QAErC,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;OAEG;IACM,KAAK,CAAC,kBAAkB,CAAC,OAAgB;QAC9C,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC;QAEpD,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,EAAG,CAAC,CAAC;QAEpC,OAAO,GAAG,CAAC;IACf,CAAC;IAEkB,MAAM;QACrB,KAAK,CAAC,MAAM,EAAE,CAAC;QAEf,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,MAAM,CAAU,KAAK,CAAC,IAAI,CAAC,GAAG,IAA6C;QACvE,OAAO,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,CAA0B,CAAC;IACxD,CAAC;CACJ;AAED,OAAO,EAAE,YAAY,IAAI,cAAc,EAAE,CAAC"}
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import type { BatchAddRequestsResult, Dictionary } from '@crawlee/types';
|
|
2
|
-
import { Configuration } from '../configuration.js';
|
|
3
|
-
import type { Request, Source } from '../request.js';
|
|
4
|
-
import type { RequestProviderOptions, RequestQueueOperationInfo, RequestQueueOperationOptions, RequestsLike } from './request_provider.js';
|
|
5
|
-
import { RequestProvider } from './request_provider.js';
|
|
6
|
-
/**
|
|
7
|
-
* Represents a queue of URLs to crawl, which is used for deep crawling of websites
|
|
8
|
-
* where you start with several URLs and then recursively
|
|
9
|
-
* follow links to other pages. The data structure supports both breadth-first and depth-first crawling orders.
|
|
10
|
-
*
|
|
11
|
-
* Each URL is represented using an instance of the {@link Request} class.
|
|
12
|
-
* The queue can only contain unique URLs. More precisely, it can only contain {@link Request} instances
|
|
13
|
-
* with distinct `uniqueKey` properties. By default, `uniqueKey` is generated from the URL, but it can also be overridden.
|
|
14
|
-
* To add a single URL multiple times to the queue,
|
|
15
|
-
* corresponding {@link Request} objects will need to have different `uniqueKey` properties.
|
|
16
|
-
*
|
|
17
|
-
* Do not instantiate this class directly, use the {@link RequestQueue.open} function instead.
|
|
18
|
-
*
|
|
19
|
-
* `RequestQueue` is used by {@link BasicCrawler}, {@link CheerioCrawler}, {@link PuppeteerCrawler}
|
|
20
|
-
* and {@link PlaywrightCrawler} as a source of URLs to crawl.
|
|
21
|
-
* Unlike {@link RequestList}, `RequestQueue` supports dynamic adding and removing of requests.
|
|
22
|
-
* On the other hand, the queue is not optimized for operations that add or remove a large number of URLs in a batch.
|
|
23
|
-
*
|
|
24
|
-
* **Example usage:**
|
|
25
|
-
*
|
|
26
|
-
* ```javascript
|
|
27
|
-
* // Open the default request queue associated with the crawler run
|
|
28
|
-
* const queue = await RequestQueue.open();
|
|
29
|
-
*
|
|
30
|
-
* // Open a named request queue
|
|
31
|
-
* const queueWithName = await RequestQueue.open('some-name');
|
|
32
|
-
*
|
|
33
|
-
* // Enqueue few requests
|
|
34
|
-
* await queue.addRequest({ url: 'http://example.com/aaa' });
|
|
35
|
-
* await queue.addRequest({ url: 'http://example.com/bbb' });
|
|
36
|
-
* await queue.addRequest({ url: 'http://example.com/foo/bar' }, { forefront: true });
|
|
37
|
-
* ```
|
|
38
|
-
* @category Sources
|
|
39
|
-
*/
|
|
40
|
-
export declare class RequestQueue extends RequestProvider {
|
|
41
|
-
private listHeadAndLockPromise;
|
|
42
|
-
private queueHasLockedRequests;
|
|
43
|
-
private shouldCheckForForefrontRequests;
|
|
44
|
-
private dequeuedRequestCount;
|
|
45
|
-
constructor(options: RequestProviderOptions, config?: Configuration);
|
|
46
|
-
/**
|
|
47
|
-
* Caches information about request to beware of unneeded addRequest() calls.
|
|
48
|
-
*/
|
|
49
|
-
protected _cacheRequest(cacheKey: string, queueOperationInfo: RequestQueueOperationInfo): void;
|
|
50
|
-
/**
|
|
51
|
-
* @inheritDoc
|
|
52
|
-
*/
|
|
53
|
-
addRequest(requestLike: Source, options?: RequestQueueOperationOptions): Promise<RequestQueueOperationInfo>;
|
|
54
|
-
/**
|
|
55
|
-
* @inheritDoc
|
|
56
|
-
*/
|
|
57
|
-
addRequests(requestsLike: RequestsLike, options?: RequestQueueOperationOptions): Promise<BatchAddRequestsResult>;
|
|
58
|
-
/**
|
|
59
|
-
* @inheritDoc
|
|
60
|
-
*/
|
|
61
|
-
fetchNextRequest<T extends Dictionary = Dictionary>(): Promise<Request<T> | null>;
|
|
62
|
-
/**
|
|
63
|
-
* @inheritDoc
|
|
64
|
-
*/
|
|
65
|
-
markRequestHandled(request: Request): Promise<RequestQueueOperationInfo | null>;
|
|
66
|
-
/**
|
|
67
|
-
* @inheritDoc
|
|
68
|
-
*/
|
|
69
|
-
isFinished(): Promise<boolean>;
|
|
70
|
-
/**
|
|
71
|
-
* @inheritDoc
|
|
72
|
-
*/
|
|
73
|
-
reclaimRequest(...args: Parameters<RequestProvider['reclaimRequest']>): ReturnType<RequestProvider['reclaimRequest']>;
|
|
74
|
-
protected ensureHeadIsNonEmpty(): Promise<void>;
|
|
75
|
-
private giveUpLock;
|
|
76
|
-
private _listHeadAndLock;
|
|
77
|
-
private getOrHydrateRequest;
|
|
78
|
-
private _prolongRequestLock;
|
|
79
|
-
protected _reset(): void;
|
|
80
|
-
protected _maybeAddRequestToQueueHead(): void;
|
|
81
|
-
protected _clearPossibleLocks(): Promise<void>;
|
|
82
|
-
/**
|
|
83
|
-
* @inheritDoc
|
|
84
|
-
*/
|
|
85
|
-
static open(...args: Parameters<typeof RequestProvider.open>): Promise<RequestQueue>;
|
|
86
|
-
}
|
|
87
|
-
//# sourceMappingURL=request_queue_v2.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request_queue_v2.d.ts","sourceRoot":"","sources":["../../src/storages/request_queue_v2.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAEpD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AAErD,OAAO,KAAK,EACR,sBAAsB,EACtB,yBAAyB,EACzB,4BAA4B,EAC5B,YAAY,EACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAiBxD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,qBAAa,YAAa,SAAQ,eAAe;IAC7C,OAAO,CAAC,sBAAsB,CAA8B;IAC5D,OAAO,CAAC,sBAAsB,CAAkC;IAChE,OAAO,CAAC,+BAA+B,CAAS;IAChD,OAAO,CAAC,oBAAoB,CAAK;gBAErB,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAkC;IAsBrF;;OAEG;cACgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,kBAAkB,EAAE,yBAAyB,GAAG,IAAI;IAevG;;OAEG;IACY,UAAU,CACrB,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,4BAAiC,GAC3C,OAAO,CAAC,yBAAyB,CAAC;IAQrC;;OAEG;IACY,WAAW,CACtB,YAAY,EAAE,YAAY,EAC1B,OAAO,GAAE,4BAAiC,GAC3C,OAAO,CAAC,sBAAsB,CAAC;IAWlC;;OAEG;IACY,gBAAgB,CAAC,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