@crawlee/core 4.0.0-beta.267 → 4.0.0-beta.268
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/package.json +6 -6
- package/storages/batched-adds.js +13 -10
- package/storages/request-queue.d.ts +5 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/core",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.268",
|
|
4
4
|
"description": "The scalable web crawling and scraping library for JavaScript/Node.js. Enables development of data extraction and web automation jobs (not only) with headless Chrome and Puppeteer.",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=22.13.0"
|
|
@@ -53,10 +53,10 @@
|
|
|
53
53
|
"@apify/log": "^3.0.1",
|
|
54
54
|
"@apify/timeout": "^1.0.1",
|
|
55
55
|
"@apify/utilities": "^3.1.0",
|
|
56
|
-
"@crawlee/fs-storage": "4.0.0-beta.
|
|
57
|
-
"@crawlee/http-client": "4.0.0-beta.
|
|
58
|
-
"@crawlee/types": "4.0.0-beta.
|
|
59
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
56
|
+
"@crawlee/fs-storage": "4.0.0-beta.268",
|
|
57
|
+
"@crawlee/http-client": "4.0.0-beta.268",
|
|
58
|
+
"@crawlee/types": "4.0.0-beta.268",
|
|
59
|
+
"@crawlee/utils": "4.0.0-beta.268",
|
|
60
60
|
"@sapphire/async-queue": "^1.5.5",
|
|
61
61
|
"@standard-schema/spec": "^1.1.0",
|
|
62
62
|
"@vladfrangu/async_event_emitter": "^2.4.7",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "9462257a02015e7ef40ebc16d8fdd0665c9554fe"
|
|
80
80
|
}
|
package/storages/batched-adds.js
CHANGED
|
@@ -14,8 +14,10 @@ import { activeStorageTransaction, withDirectStorageAccess } from './transaction
|
|
|
14
14
|
export async function drainRequestBatches(options) {
|
|
15
15
|
const { items, batchSize, waitBetweenBatchesMillis, waitForAllRequestsToBeAdded, maxNewRequests, log, processChunk, trackBackgroundBatches, } = options;
|
|
16
16
|
const deferred = activeStorageTransaction()?.policy.requestQueue === 'deferred';
|
|
17
|
+
// Leftovers are only reported when the caller waits anyway: draining an async producer just to find
|
|
18
|
+
// them could block indefinitely.
|
|
19
|
+
const reportsOverLimit = maxNewRequests !== undefined && waitForAllRequestsToBeAdded;
|
|
17
20
|
let remainingBudget = maxNewRequests ?? Infinity;
|
|
18
|
-
const requestsOverLimit = [];
|
|
19
21
|
// Never hand a chunk more than the budget allows, so an over-large final batch cannot overshoot.
|
|
20
22
|
const effectiveChunkSize = maxNewRequests !== undefined ? () => Math.min(batchSize, remainingBudget) : batchSize;
|
|
21
23
|
const chunks = peekableAsyncIterable(chunkedAsyncIterable(items, effectiveChunkSize));
|
|
@@ -28,12 +30,14 @@ export async function drainRequestBatches(options) {
|
|
|
28
30
|
return processedRequests;
|
|
29
31
|
};
|
|
30
32
|
const buildResult = async (addedRequests, waitForAll) => {
|
|
31
|
-
if (
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
if (!reportsOverLimit) {
|
|
34
|
+
return { addedRequests, waitForAllRequestsToBeAdded: waitForAll };
|
|
35
|
+
}
|
|
36
|
+
// `chunkedAsyncIterable` stops pulling once the budget-derived chunk size hits zero, so whatever
|
|
37
|
+
// is left is still sitting in `items` rather than in a chunk we have seen.
|
|
38
|
+
const requestsOverLimit = [];
|
|
39
|
+
for await (const item of items) {
|
|
40
|
+
requestsOverLimit.push(item);
|
|
37
41
|
}
|
|
38
42
|
return { addedRequests, waitForAllRequestsToBeAdded: waitForAll, requestsOverLimit };
|
|
39
43
|
};
|
|
@@ -55,9 +59,8 @@ export async function drainRequestBatches(options) {
|
|
|
55
59
|
}
|
|
56
60
|
return added;
|
|
57
61
|
};
|
|
58
|
-
//
|
|
59
|
-
|
|
60
|
-
const awaitsRemainder = waitForAllRequestsToBeAdded || maxNewRequests !== undefined || deferred;
|
|
62
|
+
// Under `deferred` a writer that finishes after commit would have nowhere to put its journal entries.
|
|
63
|
+
const awaitsRemainder = waitForAllRequestsToBeAdded || deferred;
|
|
61
64
|
// An un-awaited writer outlives the transaction scope it inherits, so it must not record into a
|
|
62
65
|
// transaction that may already be closed. It writes directly - its write-through additions were never
|
|
63
66
|
// going to be rolled back anyway - which means the requests it adds are not journaled.
|
|
@@ -303,13 +303,11 @@ export interface AddRequestsBatchedOptions extends RequestQueueOperationOptions
|
|
|
303
303
|
waitBetweenBatchesMillis?: number;
|
|
304
304
|
/**
|
|
305
305
|
* If set, only this many *actually new* requests (i.e. not already present in the queue) will be added.
|
|
306
|
-
* Once the budget is reached, remaining requests from the iterable
|
|
307
|
-
* {@link AddRequestsBatchedResult.requestsOverLimit|`requestsOverLimit`}
|
|
306
|
+
* Once the budget is reached, remaining requests from the iterable are left unconsumed, or collected in
|
|
307
|
+
* {@link AddRequestsBatchedResult.requestsOverLimit|`requestsOverLimit`} if
|
|
308
|
+
* {@link AddRequestsBatchedOptions.waitForAllRequestsToBeAdded|`waitForAllRequestsToBeAdded`} is set.
|
|
308
309
|
*
|
|
309
310
|
* This is useful in combination with `maxRequestsPerCrawl` to avoid duplicate URLs consuming the budget.
|
|
310
|
-
*
|
|
311
|
-
* **Note:** Setting this option implicitly enables {@link AddRequestsBatchedOptions.waitForAllRequestsToBeAdded|`waitForAllRequestsToBeAdded`},
|
|
312
|
-
* since all batches must complete before leftover requests can be accurately reported.
|
|
313
311
|
*/
|
|
314
312
|
maxNewRequests?: number;
|
|
315
313
|
}
|
|
@@ -335,7 +333,8 @@ export interface AddRequestsBatchedResult {
|
|
|
335
333
|
/**
|
|
336
334
|
* Requests from the input that were not added to the queue because the
|
|
337
335
|
* {@link AddRequestsBatchedOptions.maxNewRequests|`maxNewRequests`} budget was reached.
|
|
338
|
-
*
|
|
336
|
+
* `undefined` unless both `maxNewRequests` and
|
|
337
|
+
* {@link AddRequestsBatchedOptions.waitForAllRequestsToBeAdded|`waitForAllRequestsToBeAdded`} are set.
|
|
339
338
|
*/
|
|
340
339
|
requestsOverLimit?: Source[];
|
|
341
340
|
}
|