@crawlee/basic 4.0.0-beta.182 → 4.0.0-beta.183
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.
|
@@ -46,8 +46,10 @@ export interface AutoscaledPoolOptions extends TaskLoopOptions {
|
|
|
46
46
|
/**
|
|
47
47
|
* A function that performs an asynchronous resource-intensive task.
|
|
48
48
|
* The function must either be labeled `async` or return a promise.
|
|
49
|
+
* @param taskId The id the task is {@link IConcurrencySystem.tryRegisterTaskStart|booked} under, so work done
|
|
50
|
+
* inside can be correlated with what the governor sees.
|
|
49
51
|
*/
|
|
50
|
-
runTaskFunction?: () => Promise<unknown>;
|
|
52
|
+
runTaskFunction?: (taskId: string) => Promise<unknown>;
|
|
51
53
|
/**
|
|
52
54
|
* Timeout in which the `runTaskFunction` needs to finish, given in seconds.
|
|
53
55
|
* @default 0
|
|
@@ -94,6 +94,8 @@ export class AutoscaledPool {
|
|
|
94
94
|
* (possibly shared) governor's total. `pause()` and `maybeFinish()` care only about this pool draining.
|
|
95
95
|
*/
|
|
96
96
|
#ownConcurrency = 0;
|
|
97
|
+
/** Source of the ids that pair a booking with the release of the same task. */
|
|
98
|
+
#nextTaskId = 0;
|
|
97
99
|
constructor(options) {
|
|
98
100
|
const { runTaskFunction, isFinishedFunction, isTaskReadyFunction, maybeRunIntervalSecs, taskTimeoutSecs, log, concurrencySystem, consumer, } = parseArgument(options, autoscaledPoolOptionsSchema, 'AutoscaledPoolOptions');
|
|
99
101
|
this.#log = log.child({ prefix: 'AutoscaledPool' });
|
|
@@ -299,9 +301,10 @@ export class AutoscaledPool {
|
|
|
299
301
|
// No tasks could mean that we're finished with all tasks.
|
|
300
302
|
return this.maybeFinish();
|
|
301
303
|
}
|
|
304
|
+
const taskId = String(this.#nextTaskId++);
|
|
302
305
|
// - the budget still has room. Re-checked atomically, because another pool sharing the governor may have taken
|
|
303
306
|
// the last free slot while we awaited `isTaskReadyFunction` above.
|
|
304
|
-
if (!this.#concurrencySystem.tryRegisterTaskStart(this.#consumer)) {
|
|
307
|
+
if (!this.#concurrencySystem.tryRegisterTaskStart(this.#consumer, taskId)) {
|
|
305
308
|
return done();
|
|
306
309
|
}
|
|
307
310
|
this.#ownConcurrency++;
|
|
@@ -315,10 +318,10 @@ export class AutoscaledPool {
|
|
|
315
318
|
// Execute the current task.
|
|
316
319
|
this.#log.perf('Running a task.');
|
|
317
320
|
if (this.#taskTimeoutMillis > 0) {
|
|
318
|
-
await addTimeoutToPromise(async () => this.#runTaskFunction(), this.#taskTimeoutMillis, `runTaskFunction timed out after ${this.#taskTimeoutMillis / 1000} seconds.`);
|
|
321
|
+
await addTimeoutToPromise(async () => this.#runTaskFunction(taskId), this.#taskTimeoutMillis, `runTaskFunction timed out after ${this.#taskTimeoutMillis / 1000} seconds.`);
|
|
319
322
|
}
|
|
320
323
|
else {
|
|
321
|
-
await this.#runTaskFunction();
|
|
324
|
+
await this.#runTaskFunction(taskId);
|
|
322
325
|
}
|
|
323
326
|
this.#log.perf('Task finished.');
|
|
324
327
|
// Run task after the previous one finished. Only on success: a failed task rejects the pool, and
|
|
@@ -340,7 +343,7 @@ export class AutoscaledPool {
|
|
|
340
343
|
}
|
|
341
344
|
}
|
|
342
345
|
finally {
|
|
343
|
-
this.#concurrencySystem.registerTaskEnd(this.#consumer);
|
|
346
|
+
this.#concurrencySystem.registerTaskEnd(this.#consumer, taskId);
|
|
344
347
|
this.#ownConcurrency--;
|
|
345
348
|
}
|
|
346
349
|
return undefined;
|
|
@@ -131,10 +131,17 @@ export interface IConcurrencySystem {
|
|
|
131
131
|
*
|
|
132
132
|
* Must be an *atomic* (synchronous) check-and-book: several pools may share one governor, and a check separated
|
|
133
133
|
* from the booking by an `await` lets two of them claim the last free slot at once.
|
|
134
|
+
* @param taskId Identifies the booked task among the ones `consumer` has in flight, and is repeated by the
|
|
135
|
+
* {@link IConcurrencySystem.registerTaskEnd|release} — pairing the two is what lets an implementation time a
|
|
136
|
+
* task or tell which ones are still running. Nothing beyond that is promised: another consumer may be using the
|
|
137
|
+
* same id at the same time, and an id may come back around once its task has ended.
|
|
134
138
|
*/
|
|
135
|
-
tryRegisterTaskStart(consumer: ConcurrencyConsumer): boolean;
|
|
136
|
-
/**
|
|
137
|
-
|
|
139
|
+
tryRegisterTaskStart(consumer: ConcurrencyConsumer, taskId: string): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Returns a task's slot to `consumer`'s budget. Called once the task settles (resolve or reject).
|
|
142
|
+
* @param taskId The id the task was {@link IConcurrencySystem.tryRegisterTaskStart|booked} under.
|
|
143
|
+
*/
|
|
144
|
+
registerTaskEnd(consumer: ConcurrencyConsumer, taskId: string): void;
|
|
138
145
|
}
|
|
139
146
|
/**
|
|
140
147
|
* The shareable "governor" behind an {@link AutoscaledPool}: it decides whether there is free compute for one more
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/basic",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.183",
|
|
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.0.0"
|
|
@@ -42,10 +42,10 @@
|
|
|
42
42
|
"@apify/datastructures": "^3.0.1",
|
|
43
43
|
"@apify/timeout": "^1.0.1",
|
|
44
44
|
"@apify/utilities": "^3.0.1",
|
|
45
|
-
"@crawlee/core": "4.0.0-beta.
|
|
46
|
-
"@crawlee/http-client": "4.0.0-beta.
|
|
47
|
-
"@crawlee/types": "4.0.0-beta.
|
|
48
|
-
"@crawlee/utils": "4.0.0-beta.
|
|
45
|
+
"@crawlee/core": "4.0.0-beta.183",
|
|
46
|
+
"@crawlee/http-client": "4.0.0-beta.183",
|
|
47
|
+
"@crawlee/types": "4.0.0-beta.183",
|
|
48
|
+
"@crawlee/utils": "4.0.0-beta.183",
|
|
49
49
|
"@sapphire/async-queue": "^1.5.5",
|
|
50
50
|
"@standard-schema/spec": "^1.0.0",
|
|
51
51
|
"csv-stringify": "^6.5.2",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"zod": "^4.5.4"
|
|
58
58
|
},
|
|
59
59
|
"optionalDependencies": {
|
|
60
|
-
"@crawlee/impit-client": "4.0.0-beta.
|
|
60
|
+
"@crawlee/impit-client": "4.0.0-beta.183"
|
|
61
61
|
},
|
|
62
62
|
"lerna": {
|
|
63
63
|
"command": {
|
|
@@ -66,5 +66,5 @@
|
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
},
|
|
69
|
-
"gitHead": "
|
|
69
|
+
"gitHead": "3832a8d3392bba9e3e7cc6d06b9be0be4ee1ab98"
|
|
70
70
|
}
|