@crawlee/core 4.0.0-beta.8 → 4.0.0-beta.80
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 +5 -6
- package/autoscaling/autoscaled_pool.js +12 -11
- package/autoscaling/client_load_signal.d.ts +25 -0
- package/autoscaling/client_load_signal.js +36 -0
- package/autoscaling/cpu_load_signal.d.ts +28 -0
- package/autoscaling/cpu_load_signal.js +24 -0
- package/autoscaling/event_loop_load_signal.d.ts +23 -0
- package/autoscaling/event_loop_load_signal.js +35 -0
- package/autoscaling/index.d.ts +5 -1
- package/autoscaling/index.js +5 -1
- package/autoscaling/load_signal.d.ts +99 -0
- package/autoscaling/load_signal.js +135 -0
- package/autoscaling/memory_load_signal.d.ts +43 -0
- package/autoscaling/memory_load_signal.js +102 -0
- package/autoscaling/snapshotter.d.ts +35 -72
- package/autoscaling/snapshotter.js +78 -181
- package/autoscaling/system_status.d.ts +21 -36
- package/autoscaling/system_status.js +46 -84
- package/configuration.d.ts +88 -228
- package/configuration.js +162 -224
- 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 +20 -30
- package/crawlers/crawler_commons.js +12 -21
- 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 +22 -17
- package/crawlers/statistics.js +30 -26
- 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 -5
- package/events/local_event_manager.js +37 -40
- package/index.d.ts +4 -3
- package/index.js +3 -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/package.json +12 -10
- package/proxy_configuration.d.ts +14 -149
- package/proxy_configuration.js +19 -168
- package/recoverable_state.d.ts +120 -0
- package/recoverable_state.js +141 -0
- package/request.d.ts +84 -13
- package/request.js +107 -28
- package/router.d.ts +117 -15
- package/router.js +124 -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 +35 -73
- package/session_pool/session.js +46 -99
- package/session_pool/session_pool.d.ts +71 -72
- package/session_pool/session_pool.js +111 -100
- package/storages/access_checking.d.ts +0 -1
- package/storages/access_checking.js +5 -2
- package/storages/dataset.d.ts +101 -51
- package/storages/dataset.js +168 -126
- package/storages/index.d.ts +8 -7
- package/storages/index.js +6 -7
- package/storages/key_value_store.d.ts +165 -36
- package/storages/key_value_store.js +269 -122
- 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 +38 -82
- package/storages/request_list.js +65 -41
- 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 +303 -46
- package/storages/request_queue.js +629 -214
- 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 -46
- package/storages/storage_instance_manager.d.ts +91 -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 +51 -6
- package/storages/utils.js +60 -9
- 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 +1 -2
- package/typedefs.js +0 -1
- package/validators.d.ts +8 -1
- package/validators.js +8 -1
- 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
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import type { Dictionary } from '@crawlee/types';
|
|
2
|
+
import type { Request, Source } from '../request.js';
|
|
3
|
+
import type { IRequestLoader } from './request_loader.js';
|
|
4
|
+
import type { IRequestManager, RequestsLike } from './request_manager.js';
|
|
5
|
+
import type { AddRequestsBatchedOptions, AddRequestsBatchedResult, RequestQueueOperationInfo, RequestQueueOperationOptions } from './request_queue.js';
|
|
6
|
+
/**
|
|
7
|
+
* A request manager that combines a {@link IRequestLoader} (such as a `RequestList`) with a writable
|
|
8
|
+
* {@link IRequestManager} (such as a `RequestQueue`).
|
|
9
|
+
* It first reads requests from the loader and then, when needed, transfers them in batches to the manager.
|
|
10
|
+
*/
|
|
11
|
+
export declare class RequestManagerTandem implements IRequestManager {
|
|
12
|
+
private log;
|
|
13
|
+
private requestLoader;
|
|
14
|
+
private requestManagerPromise?;
|
|
15
|
+
private resolvedRequestManager?;
|
|
16
|
+
private requestManagerFactory;
|
|
17
|
+
/**
|
|
18
|
+
* The latest expected request-processing time hinted via {@link setExpectedRequestProcessingTimeSecs}.
|
|
19
|
+
* Remembered so it can be applied to the writable manager once it is lazily resolved.
|
|
20
|
+
*/
|
|
21
|
+
private expectedRequestProcessingSecs?;
|
|
22
|
+
/**
|
|
23
|
+
* @param requestLoader The read-only loader to read requests from first.
|
|
24
|
+
* @param requestManager The writable manager to transfer requests into and enqueue new ones. May be passed as a
|
|
25
|
+
* factory function so that the tandem can be constructed synchronously and the manager opened lazily on first use
|
|
26
|
+
* (e.g. a lazily-opened default {@link RequestQueue}).
|
|
27
|
+
*/
|
|
28
|
+
constructor(requestLoader: IRequestLoader, requestManager: IRequestManager | (() => IRequestManager | Promise<IRequestManager>));
|
|
29
|
+
/**
|
|
30
|
+
* Resolves the writable request manager, opening it lazily (via the factory) on first use and memoizing the result.
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private getRequestManager;
|
|
34
|
+
/**
|
|
35
|
+
* Transfers a single request from the read-only loader to the writable manager.
|
|
36
|
+
* If the transfer fails, the request is dropped (and logged) rather than reclaimed.
|
|
37
|
+
*
|
|
38
|
+
* @returns `true` if a request was successfully transferred (or there was nothing to transfer), and `false` if a
|
|
39
|
+
* transfer was attempted but failed - in which case the caller should not fetch from the manager this round.
|
|
40
|
+
* @private
|
|
41
|
+
*/
|
|
42
|
+
private transferNextRequestToQueue;
|
|
43
|
+
/**
|
|
44
|
+
* Fetches the next request from the request manager. If the manager is empty and the loader
|
|
45
|
+
* is not finished, it will transfer a request from the loader to the manager first.
|
|
46
|
+
* @inheritdoc
|
|
47
|
+
*/
|
|
48
|
+
fetchNextRequest<T extends Dictionary = Dictionary>(): Promise<Request<T> | null>;
|
|
49
|
+
/**
|
|
50
|
+
* @inheritdoc
|
|
51
|
+
*/
|
|
52
|
+
isFinished(): Promise<boolean>;
|
|
53
|
+
/**
|
|
54
|
+
* @inheritdoc
|
|
55
|
+
*/
|
|
56
|
+
isEmpty(): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* @inheritdoc
|
|
59
|
+
*/
|
|
60
|
+
getHandledCount(): Promise<number>;
|
|
61
|
+
/**
|
|
62
|
+
* @inheritdoc
|
|
63
|
+
*/
|
|
64
|
+
getTotalCount(): Promise<number>;
|
|
65
|
+
/**
|
|
66
|
+
* @inheritdoc
|
|
67
|
+
*/
|
|
68
|
+
getPendingCount(): Promise<number>;
|
|
69
|
+
/**
|
|
70
|
+
* @inheritdoc
|
|
71
|
+
*/
|
|
72
|
+
[Symbol.asyncIterator](): AsyncGenerator<Request<Dictionary>, void, unknown>;
|
|
73
|
+
/**
|
|
74
|
+
* @inheritdoc
|
|
75
|
+
*/
|
|
76
|
+
markRequestAsHandled(request: Request): Promise<RequestQueueOperationInfo | void | null>;
|
|
77
|
+
/**
|
|
78
|
+
* @inheritdoc
|
|
79
|
+
*/
|
|
80
|
+
reclaimRequest(request: Request, options?: RequestQueueOperationOptions): Promise<RequestQueueOperationInfo | null>;
|
|
81
|
+
/**
|
|
82
|
+
* @inheritdoc
|
|
83
|
+
*/
|
|
84
|
+
addRequest(requestLike: Source, options?: RequestQueueOperationOptions): Promise<RequestQueueOperationInfo>;
|
|
85
|
+
/**
|
|
86
|
+
* @inheritdoc
|
|
87
|
+
*/
|
|
88
|
+
addRequestsBatched(requests: RequestsLike, options?: AddRequestsBatchedOptions): Promise<AddRequestsBatchedResult>;
|
|
89
|
+
/**
|
|
90
|
+
* Persists the state of the underlying read-only loader, if it supports persistence.
|
|
91
|
+
* @inheritdoc
|
|
92
|
+
*/
|
|
93
|
+
persistState(): Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Purges the writable request manager so the tandem can be reused (e.g. across repeated `crawler.run()` calls).
|
|
96
|
+
* The read-only loader is immutable and cannot be purged, so only the manager side is reset.
|
|
97
|
+
* @inheritdoc
|
|
98
|
+
*/
|
|
99
|
+
purge(): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Forwards the hint to the writable request manager — that is where requests are fetched from and
|
|
102
|
+
* reserved. The manager is opened lazily, so the value is remembered and applied once it resolves.
|
|
103
|
+
* @inheritdoc
|
|
104
|
+
*/
|
|
105
|
+
setExpectedRequestProcessingTimeSecs(secs: number): Promise<void>;
|
|
106
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { serviceLocator } from '../service_locator.js';
|
|
2
|
+
/**
|
|
3
|
+
* A request manager that combines a {@link IRequestLoader} (such as a `RequestList`) with a writable
|
|
4
|
+
* {@link IRequestManager} (such as a `RequestQueue`).
|
|
5
|
+
* It first reads requests from the loader and then, when needed, transfers them in batches to the manager.
|
|
6
|
+
*/
|
|
7
|
+
export class RequestManagerTandem {
|
|
8
|
+
log;
|
|
9
|
+
requestLoader;
|
|
10
|
+
requestManagerPromise;
|
|
11
|
+
resolvedRequestManager;
|
|
12
|
+
requestManagerFactory;
|
|
13
|
+
/**
|
|
14
|
+
* The latest expected request-processing time hinted via {@link setExpectedRequestProcessingTimeSecs}.
|
|
15
|
+
* Remembered so it can be applied to the writable manager once it is lazily resolved.
|
|
16
|
+
*/
|
|
17
|
+
expectedRequestProcessingSecs;
|
|
18
|
+
/**
|
|
19
|
+
* @param requestLoader The read-only loader to read requests from first.
|
|
20
|
+
* @param requestManager The writable manager to transfer requests into and enqueue new ones. May be passed as a
|
|
21
|
+
* factory function so that the tandem can be constructed synchronously and the manager opened lazily on first use
|
|
22
|
+
* (e.g. a lazily-opened default {@link RequestQueue}).
|
|
23
|
+
*/
|
|
24
|
+
constructor(requestLoader, requestManager) {
|
|
25
|
+
this.log = serviceLocator.getLogger().child({ prefix: 'RequestManagerTandem' });
|
|
26
|
+
this.requestLoader = requestLoader;
|
|
27
|
+
this.requestManagerFactory = typeof requestManager === 'function' ? requestManager : () => requestManager;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Resolves the writable request manager, opening it lazily (via the factory) on first use and memoizing the result.
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
async getRequestManager() {
|
|
34
|
+
if (this.resolvedRequestManager === undefined) {
|
|
35
|
+
this.requestManagerPromise ??= Promise.resolve(this.requestManagerFactory());
|
|
36
|
+
this.resolvedRequestManager = await this.requestManagerPromise;
|
|
37
|
+
// Apply any hint received before the manager was resolved.
|
|
38
|
+
if (this.expectedRequestProcessingSecs !== undefined) {
|
|
39
|
+
await this.resolvedRequestManager.setExpectedRequestProcessingTimeSecs?.(this.expectedRequestProcessingSecs);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return this.resolvedRequestManager;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Transfers a single request from the read-only loader to the writable manager.
|
|
46
|
+
* If the transfer fails, the request is dropped (and logged) rather than reclaimed.
|
|
47
|
+
*
|
|
48
|
+
* @returns `true` if a request was successfully transferred (or there was nothing to transfer), and `false` if a
|
|
49
|
+
* transfer was attempted but failed - in which case the caller should not fetch from the manager this round.
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
async transferNextRequestToQueue() {
|
|
53
|
+
const request = await this.requestLoader.fetchNextRequest();
|
|
54
|
+
if (request === null) {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
const requestManager = await this.getRequestManager();
|
|
58
|
+
try {
|
|
59
|
+
await requestManager.addRequest(request, { forefront: true });
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
catch (error) {
|
|
63
|
+
this.log.exception(error, 'Adding request from the RequestLoader to the RequestManager failed, the request has been dropped.', { url: request.url, uniqueKey: request.uniqueKey });
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
finally {
|
|
67
|
+
// Mark it as handled so that the request doesn't get stuck in the `inProgress` state in the loader.
|
|
68
|
+
await this.requestLoader.markRequestAsHandled(request);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Fetches the next request from the request manager. If the manager is empty and the loader
|
|
73
|
+
* is not finished, it will transfer a request from the loader to the manager first.
|
|
74
|
+
* @inheritdoc
|
|
75
|
+
*/
|
|
76
|
+
async fetchNextRequest() {
|
|
77
|
+
// First, try to transfer a request from the requestList
|
|
78
|
+
const [listEmpty, listFinished] = await Promise.all([
|
|
79
|
+
this.requestLoader.isEmpty(),
|
|
80
|
+
this.requestLoader.isFinished(),
|
|
81
|
+
]);
|
|
82
|
+
if (!listEmpty && !listFinished) {
|
|
83
|
+
// If the transfer failed, the request was dropped; don't fetch from the manager this round (matching
|
|
84
|
+
// crawlee-python behaviour). The next `fetchNextRequest()` call will pick up where we left off.
|
|
85
|
+
if (!(await this.transferNextRequestToQueue())) {
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// Try to fetch from manager after the transfer
|
|
90
|
+
return (await this.getRequestManager()).fetchNextRequest();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @inheritdoc
|
|
94
|
+
*/
|
|
95
|
+
async isFinished() {
|
|
96
|
+
const requestManager = await this.getRequestManager();
|
|
97
|
+
const storagesFinished = await Promise.all([this.requestLoader.isFinished(), requestManager.isFinished()]);
|
|
98
|
+
return storagesFinished.every(Boolean);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @inheritdoc
|
|
102
|
+
*/
|
|
103
|
+
async isEmpty() {
|
|
104
|
+
const requestManager = await this.getRequestManager();
|
|
105
|
+
const storagesEmpty = await Promise.all([this.requestLoader.isEmpty(), requestManager.isEmpty()]);
|
|
106
|
+
return storagesEmpty.every(Boolean);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @inheritdoc
|
|
110
|
+
*/
|
|
111
|
+
async getHandledCount() {
|
|
112
|
+
// Since one of the stores needs to have priority when both are present, we query the request manager - the request loader will first be dumped into the manager and then left empty.
|
|
113
|
+
return (await this.getRequestManager()).getHandledCount();
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* @inheritdoc
|
|
117
|
+
*/
|
|
118
|
+
async getTotalCount() {
|
|
119
|
+
const requestManager = await this.getRequestManager();
|
|
120
|
+
const [managerTotal, loaderTotal] = await Promise.all([
|
|
121
|
+
requestManager.getTotalCount(),
|
|
122
|
+
// count only pending to avoid double counting, requests marked as "handled" have been moved to requestManager
|
|
123
|
+
this.requestLoader.getPendingCount(),
|
|
124
|
+
]);
|
|
125
|
+
return managerTotal + loaderTotal;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* @inheritdoc
|
|
129
|
+
*/
|
|
130
|
+
async getPendingCount() {
|
|
131
|
+
const requestManager = await this.getRequestManager();
|
|
132
|
+
const [managerPending, loaderPending] = await Promise.all([
|
|
133
|
+
requestManager.getPendingCount(),
|
|
134
|
+
this.requestLoader.getPendingCount(),
|
|
135
|
+
]);
|
|
136
|
+
return managerPending + loaderPending;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @inheritdoc
|
|
140
|
+
*/
|
|
141
|
+
async *[Symbol.asyncIterator]() {
|
|
142
|
+
while (true) {
|
|
143
|
+
const req = await this.fetchNextRequest();
|
|
144
|
+
if (!req)
|
|
145
|
+
break;
|
|
146
|
+
yield req;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* @inheritdoc
|
|
151
|
+
*/
|
|
152
|
+
async markRequestAsHandled(request) {
|
|
153
|
+
return (await this.getRequestManager()).markRequestAsHandled(request);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* @inheritdoc
|
|
157
|
+
*/
|
|
158
|
+
async reclaimRequest(request, options) {
|
|
159
|
+
return (await this.getRequestManager()).reclaimRequest(request, options);
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* @inheritdoc
|
|
163
|
+
*/
|
|
164
|
+
async addRequest(requestLike, options) {
|
|
165
|
+
return (await this.getRequestManager()).addRequest(requestLike, options);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* @inheritdoc
|
|
169
|
+
*/
|
|
170
|
+
async addRequestsBatched(requests, options) {
|
|
171
|
+
return (await this.getRequestManager()).addRequestsBatched(requests, options);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Persists the state of the underlying read-only loader, if it supports persistence.
|
|
175
|
+
* @inheritdoc
|
|
176
|
+
*/
|
|
177
|
+
async persistState() {
|
|
178
|
+
await this.requestLoader.persistState?.();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Purges the writable request manager so the tandem can be reused (e.g. across repeated `crawler.run()` calls).
|
|
182
|
+
* The read-only loader is immutable and cannot be purged, so only the manager side is reset.
|
|
183
|
+
* @inheritdoc
|
|
184
|
+
*/
|
|
185
|
+
async purge() {
|
|
186
|
+
await (await this.getRequestManager()).purge?.();
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Forwards the hint to the writable request manager — that is where requests are fetched from and
|
|
190
|
+
* reserved. The manager is opened lazily, so the value is remembered and applied once it resolves.
|
|
191
|
+
* @inheritdoc
|
|
192
|
+
*/
|
|
193
|
+
async setExpectedRequestProcessingTimeSecs(secs) {
|
|
194
|
+
this.expectedRequestProcessingSecs = secs;
|
|
195
|
+
await this.resolvedRequestManager?.setExpectedRequestProcessingTimeSecs?.(secs);
|
|
196
|
+
}
|
|
197
|
+
}
|