@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.
Files changed (257) hide show
  1. package/README.md +17 -13
  2. package/autoscaling/autoscaled_pool.d.ts +5 -6
  3. package/autoscaling/autoscaled_pool.js +12 -11
  4. package/autoscaling/client_load_signal.d.ts +25 -0
  5. package/autoscaling/client_load_signal.js +36 -0
  6. package/autoscaling/cpu_load_signal.d.ts +28 -0
  7. package/autoscaling/cpu_load_signal.js +24 -0
  8. package/autoscaling/event_loop_load_signal.d.ts +23 -0
  9. package/autoscaling/event_loop_load_signal.js +35 -0
  10. package/autoscaling/index.d.ts +5 -1
  11. package/autoscaling/index.js +5 -1
  12. package/autoscaling/load_signal.d.ts +99 -0
  13. package/autoscaling/load_signal.js +135 -0
  14. package/autoscaling/memory_load_signal.d.ts +43 -0
  15. package/autoscaling/memory_load_signal.js +102 -0
  16. package/autoscaling/snapshotter.d.ts +35 -72
  17. package/autoscaling/snapshotter.js +78 -181
  18. package/autoscaling/system_status.d.ts +21 -36
  19. package/autoscaling/system_status.js +46 -84
  20. package/configuration.d.ts +88 -228
  21. package/configuration.js +162 -224
  22. package/cookie_utils.d.ts +4 -3
  23. package/cookie_utils.js +20 -13
  24. package/crawlers/context_pipeline.d.ts +70 -0
  25. package/crawlers/context_pipeline.js +122 -0
  26. package/crawlers/crawler_commons.d.ts +20 -30
  27. package/crawlers/crawler_commons.js +12 -21
  28. package/crawlers/crawler_utils.d.ts +2 -3
  29. package/crawlers/crawler_utils.js +1 -2
  30. package/crawlers/error_snapshotter.d.ts +3 -3
  31. package/crawlers/error_snapshotter.js +2 -3
  32. package/crawlers/error_tracker.d.ts +2 -2
  33. package/crawlers/error_tracker.js +0 -1
  34. package/crawlers/index.d.ts +1 -2
  35. package/crawlers/index.js +1 -2
  36. package/crawlers/internals/types.d.ts +7 -0
  37. package/crawlers/internals/types.js +1 -0
  38. package/crawlers/statistics.d.ts +22 -17
  39. package/crawlers/statistics.js +30 -26
  40. package/enqueue_links/enqueue_links.d.ts +44 -22
  41. package/enqueue_links/enqueue_links.js +51 -30
  42. package/enqueue_links/index.d.ts +0 -1
  43. package/enqueue_links/index.js +0 -1
  44. package/enqueue_links/shared.d.ts +25 -9
  45. package/enqueue_links/shared.js +69 -38
  46. package/errors.d.ts +53 -4
  47. package/errors.js +70 -5
  48. package/events/event_manager.d.ts +34 -8
  49. package/events/event_manager.js +8 -10
  50. package/events/index.d.ts +0 -1
  51. package/events/index.js +0 -1
  52. package/events/local_event_manager.d.ts +15 -5
  53. package/events/local_event_manager.js +37 -40
  54. package/index.d.ts +4 -3
  55. package/index.js +3 -2
  56. package/log.d.ts +82 -3
  57. package/log.js +102 -1
  58. package/memory-storage/consts.d.ts +4 -0
  59. package/memory-storage/consts.js +4 -0
  60. package/memory-storage/index.d.ts +1 -0
  61. package/memory-storage/index.js +1 -0
  62. package/memory-storage/memory-storage.d.ts +46 -0
  63. package/memory-storage/memory-storage.js +136 -0
  64. package/memory-storage/resource-clients/common/base-client.d.ts +4 -0
  65. package/memory-storage/resource-clients/common/base-client.js +6 -0
  66. package/memory-storage/resource-clients/dataset.d.ts +40 -0
  67. package/memory-storage/resource-clients/dataset.js +113 -0
  68. package/memory-storage/resource-clients/key-value-store.d.ts +63 -0
  69. package/memory-storage/resource-clients/key-value-store.js +203 -0
  70. package/memory-storage/resource-clients/request-queue.d.ts +96 -0
  71. package/memory-storage/resource-clients/request-queue.js +421 -0
  72. package/memory-storage/utils.d.ts +17 -0
  73. package/memory-storage/utils.js +42 -0
  74. package/package.json +12 -10
  75. package/proxy_configuration.d.ts +14 -149
  76. package/proxy_configuration.js +19 -168
  77. package/recoverable_state.d.ts +120 -0
  78. package/recoverable_state.js +141 -0
  79. package/request.d.ts +84 -13
  80. package/request.js +107 -28
  81. package/router.d.ts +117 -15
  82. package/router.js +124 -30
  83. package/serialization.d.ts +0 -1
  84. package/serialization.js +1 -2
  85. package/service_locator.d.ts +156 -0
  86. package/service_locator.js +238 -0
  87. package/session_pool/consts.d.ts +1 -2
  88. package/session_pool/consts.js +1 -2
  89. package/session_pool/errors.d.ts +0 -1
  90. package/session_pool/errors.js +0 -1
  91. package/session_pool/fingerprint.d.ts +9 -0
  92. package/session_pool/fingerprint.js +30 -0
  93. package/session_pool/index.d.ts +0 -2
  94. package/session_pool/index.js +0 -2
  95. package/session_pool/session.d.ts +35 -73
  96. package/session_pool/session.js +46 -99
  97. package/session_pool/session_pool.d.ts +71 -72
  98. package/session_pool/session_pool.js +111 -100
  99. package/storages/access_checking.d.ts +0 -1
  100. package/storages/access_checking.js +5 -2
  101. package/storages/dataset.d.ts +101 -51
  102. package/storages/dataset.js +168 -126
  103. package/storages/index.d.ts +8 -7
  104. package/storages/index.js +6 -7
  105. package/storages/key_value_store.d.ts +165 -36
  106. package/storages/key_value_store.js +269 -122
  107. package/storages/key_value_store_codec.d.ts +32 -0
  108. package/storages/key_value_store_codec.js +113 -0
  109. package/storages/request_dedup_cache.d.ts +23 -0
  110. package/storages/request_dedup_cache.js +48 -0
  111. package/storages/request_list.d.ts +38 -82
  112. package/storages/request_list.js +65 -41
  113. package/storages/request_loader.d.ts +96 -0
  114. package/storages/request_loader.js +1 -0
  115. package/storages/request_manager.d.ts +33 -0
  116. package/storages/request_manager.js +1 -0
  117. package/storages/request_manager_tandem.d.ts +106 -0
  118. package/storages/request_manager_tandem.js +197 -0
  119. package/storages/request_queue.d.ts +303 -46
  120. package/storages/request_queue.js +629 -214
  121. package/storages/{sitemap_request_list.d.ts → sitemap_request_loader.d.ts} +28 -24
  122. package/storages/{sitemap_request_list.js → sitemap_request_loader.js} +49 -46
  123. package/storages/storage_instance_manager.d.ts +91 -0
  124. package/storages/storage_instance_manager.js +258 -0
  125. package/storages/storage_stats.d.ts +48 -0
  126. package/storages/storage_stats.js +29 -0
  127. package/storages/utils.d.ts +51 -6
  128. package/storages/utils.js +60 -9
  129. package/system-info/cpu-info.d.ts +67 -0
  130. package/system-info/cpu-info.js +216 -0
  131. package/system-info/memory-info.d.ts +31 -0
  132. package/system-info/memory-info.js +115 -0
  133. package/system-info/ps-tree.d.ts +17 -0
  134. package/system-info/ps-tree.js +144 -0
  135. package/system-info/runtime.d.ts +14 -0
  136. package/system-info/runtime.js +80 -0
  137. package/typedefs.d.ts +1 -2
  138. package/typedefs.js +0 -1
  139. package/validators.d.ts +8 -1
  140. package/validators.js +8 -1
  141. package/autoscaling/autoscaled_pool.d.ts.map +0 -1
  142. package/autoscaling/autoscaled_pool.js.map +0 -1
  143. package/autoscaling/index.d.ts.map +0 -1
  144. package/autoscaling/index.js.map +0 -1
  145. package/autoscaling/snapshotter.d.ts.map +0 -1
  146. package/autoscaling/snapshotter.js.map +0 -1
  147. package/autoscaling/system_status.d.ts.map +0 -1
  148. package/autoscaling/system_status.js.map +0 -1
  149. package/configuration.d.ts.map +0 -1
  150. package/configuration.js.map +0 -1
  151. package/cookie_utils.d.ts.map +0 -1
  152. package/cookie_utils.js.map +0 -1
  153. package/crawlers/crawler_commons.d.ts.map +0 -1
  154. package/crawlers/crawler_commons.js.map +0 -1
  155. package/crawlers/crawler_extension.d.ts +0 -12
  156. package/crawlers/crawler_extension.d.ts.map +0 -1
  157. package/crawlers/crawler_extension.js +0 -14
  158. package/crawlers/crawler_extension.js.map +0 -1
  159. package/crawlers/crawler_utils.d.ts.map +0 -1
  160. package/crawlers/crawler_utils.js.map +0 -1
  161. package/crawlers/error_snapshotter.d.ts.map +0 -1
  162. package/crawlers/error_snapshotter.js.map +0 -1
  163. package/crawlers/error_tracker.d.ts.map +0 -1
  164. package/crawlers/error_tracker.js.map +0 -1
  165. package/crawlers/index.d.ts.map +0 -1
  166. package/crawlers/index.js.map +0 -1
  167. package/crawlers/statistics.d.ts.map +0 -1
  168. package/crawlers/statistics.js.map +0 -1
  169. package/enqueue_links/enqueue_links.d.ts.map +0 -1
  170. package/enqueue_links/enqueue_links.js.map +0 -1
  171. package/enqueue_links/index.d.ts.map +0 -1
  172. package/enqueue_links/index.js.map +0 -1
  173. package/enqueue_links/shared.d.ts.map +0 -1
  174. package/enqueue_links/shared.js.map +0 -1
  175. package/errors.d.ts.map +0 -1
  176. package/errors.js.map +0 -1
  177. package/events/event_manager.d.ts.map +0 -1
  178. package/events/event_manager.js.map +0 -1
  179. package/events/index.d.ts.map +0 -1
  180. package/events/index.js.map +0 -1
  181. package/events/local_event_manager.d.ts.map +0 -1
  182. package/events/local_event_manager.js.map +0 -1
  183. package/http_clients/base-http-client.d.ts +0 -134
  184. package/http_clients/base-http-client.d.ts.map +0 -1
  185. package/http_clients/base-http-client.js +0 -33
  186. package/http_clients/base-http-client.js.map +0 -1
  187. package/http_clients/form-data-like.d.ts +0 -67
  188. package/http_clients/form-data-like.d.ts.map +0 -1
  189. package/http_clients/form-data-like.js +0 -5
  190. package/http_clients/form-data-like.js.map +0 -1
  191. package/http_clients/got-scraping-http-client.d.ts +0 -15
  192. package/http_clients/got-scraping-http-client.d.ts.map +0 -1
  193. package/http_clients/got-scraping-http-client.js +0 -69
  194. package/http_clients/got-scraping-http-client.js.map +0 -1
  195. package/http_clients/index.d.ts +0 -3
  196. package/http_clients/index.d.ts.map +0 -1
  197. package/http_clients/index.js +0 -3
  198. package/http_clients/index.js.map +0 -1
  199. package/index.d.ts.map +0 -1
  200. package/index.js.map +0 -1
  201. package/log.d.ts.map +0 -1
  202. package/log.js.map +0 -1
  203. package/proxy_configuration.d.ts.map +0 -1
  204. package/proxy_configuration.js.map +0 -1
  205. package/request.d.ts.map +0 -1
  206. package/request.js.map +0 -1
  207. package/router.d.ts.map +0 -1
  208. package/router.js.map +0 -1
  209. package/serialization.d.ts.map +0 -1
  210. package/serialization.js.map +0 -1
  211. package/session_pool/consts.d.ts.map +0 -1
  212. package/session_pool/consts.js.map +0 -1
  213. package/session_pool/errors.d.ts.map +0 -1
  214. package/session_pool/errors.js.map +0 -1
  215. package/session_pool/events.d.ts +0 -3
  216. package/session_pool/events.d.ts.map +0 -1
  217. package/session_pool/events.js +0 -3
  218. package/session_pool/events.js.map +0 -1
  219. package/session_pool/index.d.ts.map +0 -1
  220. package/session_pool/index.js.map +0 -1
  221. package/session_pool/session.d.ts.map +0 -1
  222. package/session_pool/session.js.map +0 -1
  223. package/session_pool/session_pool.d.ts.map +0 -1
  224. package/session_pool/session_pool.js.map +0 -1
  225. package/storages/access_checking.d.ts.map +0 -1
  226. package/storages/access_checking.js.map +0 -1
  227. package/storages/dataset.d.ts.map +0 -1
  228. package/storages/dataset.js.map +0 -1
  229. package/storages/index.d.ts.map +0 -1
  230. package/storages/index.js.map +0 -1
  231. package/storages/key_value_store.d.ts.map +0 -1
  232. package/storages/key_value_store.js.map +0 -1
  233. package/storages/request_list.d.ts.map +0 -1
  234. package/storages/request_list.js.map +0 -1
  235. package/storages/request_provider.d.ts +0 -307
  236. package/storages/request_provider.d.ts.map +0 -1
  237. package/storages/request_provider.js +0 -555
  238. package/storages/request_provider.js.map +0 -1
  239. package/storages/request_queue.d.ts.map +0 -1
  240. package/storages/request_queue.js.map +0 -1
  241. package/storages/request_queue_v2.d.ts +0 -87
  242. package/storages/request_queue_v2.d.ts.map +0 -1
  243. package/storages/request_queue_v2.js +0 -438
  244. package/storages/request_queue_v2.js.map +0 -1
  245. package/storages/sitemap_request_list.d.ts.map +0 -1
  246. package/storages/sitemap_request_list.js.map +0 -1
  247. package/storages/storage_manager.d.ts +0 -58
  248. package/storages/storage_manager.d.ts.map +0 -1
  249. package/storages/storage_manager.js +0 -105
  250. package/storages/storage_manager.js.map +0 -1
  251. package/storages/utils.d.ts.map +0 -1
  252. package/storages/utils.js.map +0 -1
  253. package/tsconfig.build.tsbuildinfo +0 -1
  254. package/typedefs.d.ts.map +0 -1
  255. package/typedefs.js.map +0 -1
  256. package/validators.d.ts.map +0 -1
  257. 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
+ }