@crawlee/core 4.0.0-beta.170 → 4.0.0-beta.171

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 (76) hide show
  1. package/errors.d.ts +0 -57
  2. package/errors.js +0 -71
  3. package/events/index.d.ts +1 -0
  4. package/events/system_info.d.ts +38 -0
  5. package/index.d.ts +1 -7
  6. package/index.js +1 -7
  7. package/internal.d.ts +8 -0
  8. package/internal.js +9 -0
  9. package/package.json +7 -9
  10. package/request.d.ts +4 -2
  11. package/storages/index.d.ts +0 -2
  12. package/storages/index.js +0 -2
  13. package/autoscaling/autoscaled_pool.d.ts +0 -196
  14. package/autoscaling/autoscaled_pool.js +0 -386
  15. package/autoscaling/concurrency_system.d.ts +0 -268
  16. package/autoscaling/concurrency_system.js +0 -364
  17. package/autoscaling/cpu_load_signal.d.ts +0 -43
  18. package/autoscaling/cpu_load_signal.js +0 -47
  19. package/autoscaling/event_loop_load_signal.d.ts +0 -51
  20. package/autoscaling/event_loop_load_signal.js +0 -60
  21. package/autoscaling/index.d.ts +0 -9
  22. package/autoscaling/index.js +0 -9
  23. package/autoscaling/load_signal.d.ts +0 -98
  24. package/autoscaling/load_signal.js +0 -103
  25. package/autoscaling/memory_load_signal.d.ts +0 -47
  26. package/autoscaling/memory_load_signal.js +0 -106
  27. package/autoscaling/snapshotter.d.ts +0 -84
  28. package/autoscaling/snapshotter.js +0 -67
  29. package/autoscaling/storage_backend_load_signal.d.ts +0 -56
  30. package/autoscaling/storage_backend_load_signal.js +0 -73
  31. package/autoscaling/system_status.d.ts +0 -159
  32. package/autoscaling/system_status.js +0 -139
  33. package/autoscaling/weighted_avg.d.ts +0 -5
  34. package/autoscaling/weighted_avg.js +0 -14
  35. package/cookie_utils.d.ts +0 -44
  36. package/cookie_utils.js +0 -122
  37. package/crawlers/context_pipeline.d.ts +0 -70
  38. package/crawlers/context_pipeline.js +0 -122
  39. package/crawlers/crawler_commons.d.ts +0 -199
  40. package/crawlers/error_snapshotter.d.ts +0 -57
  41. package/crawlers/error_snapshotter.js +0 -117
  42. package/crawlers/error_tracker.d.ts +0 -54
  43. package/crawlers/error_tracker.js +0 -308
  44. package/crawlers/index.d.ts +0 -5
  45. package/crawlers/index.js +0 -4
  46. package/crawlers/internals/types.d.ts +0 -7
  47. package/crawlers/internals/types.js +0 -1
  48. package/crawlers/statistics.d.ts +0 -319
  49. package/crawlers/statistics.js +0 -527
  50. package/enqueue_links/enqueue_links.d.ts +0 -156
  51. package/enqueue_links/enqueue_links.js +0 -77
  52. package/enqueue_links/index.d.ts +0 -2
  53. package/enqueue_links/index.js +0 -2
  54. package/enqueue_links/shared.d.ts +0 -100
  55. package/enqueue_links/shared.js +0 -259
  56. package/http.d.ts +0 -9
  57. package/http.js +0 -28
  58. package/router.d.ts +0 -306
  59. package/router.js +0 -309
  60. package/session_pool/consts.d.ts +0 -3
  61. package/session_pool/consts.js +0 -3
  62. package/session_pool/errors.d.ts +0 -7
  63. package/session_pool/errors.js +0 -11
  64. package/session_pool/fingerprint.d.ts +0 -9
  65. package/session_pool/fingerprint.js +0 -30
  66. package/session_pool/index.d.ts +0 -4
  67. package/session_pool/index.js +0 -4
  68. package/session_pool/session.d.ts +0 -153
  69. package/session_pool/session.js +0 -221
  70. package/session_pool/session_pool.d.ts +0 -242
  71. package/session_pool/session_pool.js +0 -431
  72. package/storages/sitemap_request_loader.d.ts +0 -197
  73. package/storages/sitemap_request_loader.js +0 -439
  74. package/storages/throttling_request_manager.d.ts +0 -223
  75. package/storages/throttling_request_manager.js +0 -835
  76. /package/{crawlers/crawler_commons.js → events/system_info.js} +0 -0
package/errors.d.ts CHANGED
@@ -9,11 +9,6 @@ export declare class NonRetryableError extends Error {
9
9
  */
10
10
  export declare class CriticalError extends NonRetryableError {
11
11
  }
12
- /**
13
- * @ignore
14
- */
15
- export declare class MissingRouteError extends CriticalError {
16
- }
17
12
  /**
18
13
  * A schema validation issue, structurally compatible with `StandardSchemaV1.Issue`. Declared here so that
19
14
  * error types do not have to depend on `@standard-schema/spec`.
@@ -45,34 +40,6 @@ export declare class StateValidationError extends Error {
45
40
  readonly issues: readonly SchemaIssue[];
46
41
  constructor(persistStateKey: string, issues: readonly SchemaIssue[]);
47
42
  }
48
- /**
49
- * Errors of `RetryRequestError` type will always be retried by the crawler.
50
- *
51
- * *This error overrides the `maxRequestRetries` option, i.e. the request can be retried indefinitely until it succeeds.*
52
- */
53
- export declare class RetryRequestError extends Error {
54
- constructor(message?: string);
55
- }
56
- /**
57
- * Thrown when a domain has rate-limited us and the request should simply be attempted again later.
58
- *
59
- * The request is reclaimed without recording a failure: it costs neither a retry nor session reputation, because
60
- * nothing about the request or the session was at fault. A {@link ThrottlingRequestManager} holds it back until
61
- * the domain's backoff expires, so retries are paced rather than immediate.
62
- */
63
- export declare class RequestThrottledError extends RetryRequestError {
64
- constructor(message?: string);
65
- }
66
- /**
67
- * Thrown when a domain has rate-limited us for so long that no request has got through, and the crawl is
68
- * abandoned rather than kept waiting.
69
- *
70
- * Waiting longer will not help: at this point the concurrency is too high for the domain, or it has blocked us.
71
- * The affected requests are deliberately left in their queue, so re-running the crawl without purging storages
72
- * resumes them once the domain recovers.
73
- */
74
- export declare class PersistentRateLimitError extends CriticalError {
75
- }
76
43
  /**
77
44
  * Errors of `SessionError` type retire the session associated with the request and trigger a regular retry.
78
45
  *
@@ -81,24 +48,6 @@ export declare class PersistentRateLimitError extends CriticalError {
81
48
  export declare class SessionError extends Error {
82
49
  constructor(message?: string);
83
50
  }
84
- /**
85
- * Thrown when a requested session is not found in the referenced SessionPool.
86
- */
87
- export declare class MissingSessionError extends Error {
88
- constructor(sessionId?: string);
89
- }
90
- export declare class ContextPipelineInterruptedError extends Error {
91
- constructor(message?: string);
92
- }
93
- export declare class ContextPipelineInitializationError extends Error {
94
- constructor(error: unknown, options?: ErrorOptions);
95
- }
96
- export declare class ContextPipelineCleanupError extends CriticalError {
97
- constructor(error: unknown, options?: ErrorOptions);
98
- }
99
- export declare class RequestHandlerError extends Error {
100
- constructor(error: unknown, options?: ErrorOptions);
101
- }
102
51
  /**
103
52
  * Wraps the failure of a callback registered with {@link StorageTransaction.afterCommit|`afterCommit`}
104
53
  * that ran after the request's writes had already been committed.
@@ -115,9 +64,3 @@ export declare class AfterCommitError extends NonRetryableError {
115
64
  export declare class ServiceConflictError extends Error {
116
65
  constructor(serviceName: string, newValue: unknown, existingValue: unknown);
117
66
  }
118
- /**
119
- * Thrown by crawlers when `skipNavigation` is used on a request.
120
- * Subclasses can catch this error to skip their own navigation-dependent logic.
121
- */
122
- export declare class NavigationSkippedError extends NonRetryableError {
123
- }
package/errors.js CHANGED
@@ -10,11 +10,6 @@ export class NonRetryableError extends Error {
10
10
  */
11
11
  export class CriticalError extends NonRetryableError {
12
12
  }
13
- /**
14
- * @ignore
15
- */
16
- export class MissingRouteError extends CriticalError {
17
- }
18
13
  function formatIssues(issues) {
19
14
  return issues
20
15
  .map((issue) => {
@@ -54,38 +49,6 @@ export class StateValidationError extends Error {
54
49
  this.issues = issues;
55
50
  }
56
51
  }
57
- /**
58
- * Errors of `RetryRequestError` type will always be retried by the crawler.
59
- *
60
- * *This error overrides the `maxRequestRetries` option, i.e. the request can be retried indefinitely until it succeeds.*
61
- */
62
- export class RetryRequestError extends Error {
63
- constructor(message) {
64
- super(message ?? "Request is being retried at the user's request");
65
- }
66
- }
67
- /**
68
- * Thrown when a domain has rate-limited us and the request should simply be attempted again later.
69
- *
70
- * The request is reclaimed without recording a failure: it costs neither a retry nor session reputation, because
71
- * nothing about the request or the session was at fault. A {@link ThrottlingRequestManager} holds it back until
72
- * the domain's backoff expires, so retries are paced rather than immediate.
73
- */
74
- export class RequestThrottledError extends RetryRequestError {
75
- constructor(message) {
76
- super(message ?? 'Request is being retried later because its domain is rate-limiting us');
77
- }
78
- }
79
- /**
80
- * Thrown when a domain has rate-limited us for so long that no request has got through, and the crawl is
81
- * abandoned rather than kept waiting.
82
- *
83
- * Waiting longer will not help: at this point the concurrency is too high for the domain, or it has blocked us.
84
- * The affected requests are deliberately left in their queue, so re-running the crawl without purging storages
85
- * resumes them once the domain recovers.
86
- */
87
- export class PersistentRateLimitError extends CriticalError {
88
- }
89
52
  /**
90
53
  * Errors of `SessionError` type retire the session associated with the request and trigger a regular retry.
91
54
  *
@@ -96,34 +59,6 @@ export class SessionError extends Error {
96
59
  super(`Detected a session error, retiring session... ${message ? `\n${message}` : ''}`);
97
60
  }
98
61
  }
99
- /**
100
- * Thrown when a requested session is not found in the referenced SessionPool.
101
- */
102
- export class MissingSessionError extends Error {
103
- constructor(sessionId) {
104
- super(`The current SessionPool instance couldn't find a valid session${sessionId ? ` for the following id: ${sessionId}.` : '.'}`);
105
- }
106
- }
107
- export class ContextPipelineInterruptedError extends Error {
108
- constructor(message) {
109
- super(`Request handling was interrupted during context initialization ${message ? ` - ${message}` : ''}`);
110
- }
111
- }
112
- export class ContextPipelineInitializationError extends Error {
113
- constructor(error, options) {
114
- super(undefined, { cause: error, ...options });
115
- }
116
- }
117
- export class ContextPipelineCleanupError extends CriticalError {
118
- constructor(error, options) {
119
- super(undefined, { cause: error, ...options });
120
- }
121
- }
122
- export class RequestHandlerError extends Error {
123
- constructor(error, options) {
124
- super(undefined, { cause: error, ...options });
125
- }
126
- }
127
62
  /**
128
63
  * Wraps the failure of a callback registered with {@link StorageTransaction.afterCommit|`afterCommit`}
129
64
  * that ran after the request's writes had already been committed.
@@ -145,9 +80,3 @@ export class ServiceConflictError extends Error {
145
80
  `Existing value: ${inspectValue(existingValue)}, attempted new value: ${inspectValue(newValue)}.`);
146
81
  }
147
82
  }
148
- /**
149
- * Thrown by crawlers when `skipNavigation` is used on a request.
150
- * Subclasses can catch this error to skip their own navigation-dependent logic.
151
- */
152
- export class NavigationSkippedError extends NonRetryableError {
153
- }
package/events/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export * from './event_manager.js';
2
2
  export * from './local_event_manager.js';
3
+ export type * from './system_info.js';
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Represents the current status of the system.
3
+ */
4
+ export interface SystemInfo {
5
+ /** If false, system is being overloaded. */
6
+ isSystemIdle: boolean;
7
+ memInfo: LoadSignalInfo;
8
+ eventLoopInfo: LoadSignalInfo;
9
+ cpuInfo: LoadSignalInfo;
10
+ storageBackendInfo: LoadSignalInfo;
11
+ memTotalBytes?: number;
12
+ memCurrentBytes?: number;
13
+ /**
14
+ * Platform only property
15
+ * @internal
16
+ */
17
+ cpuCurrentUsage?: number;
18
+ /**
19
+ * Platform only property
20
+ * @internal
21
+ */
22
+ isCpuOverloaded?: boolean;
23
+ /**
24
+ * Platform only property
25
+ * @internal
26
+ */
27
+ createdAt?: Date;
28
+ /**
29
+ * Status of additional load signals beyond the built-in four.
30
+ * Keys are `LoadSignal.name` values, values are overload info.
31
+ */
32
+ loadSignalInfo?: Record<string, LoadSignalInfo>;
33
+ }
34
+ export interface LoadSignalInfo {
35
+ isOverloaded: boolean;
36
+ limitRatio: number;
37
+ actualRatio: number;
38
+ }
package/index.d.ts CHANGED
@@ -1,22 +1,16 @@
1
1
  export * from './debug.js';
2
2
  export * from './errors.js';
3
- export * from './autoscaling/index.js';
4
3
  export * from './configuration.js';
5
4
  export * from './service_locator.js';
6
- export * from './crawlers/index.js';
7
- export * from './enqueue_links/index.js';
8
5
  export * from './events/index.js';
9
6
  export * from './log.js';
10
7
  export * from './owned_or_injected.js';
11
8
  export * from './proxy_configuration.js';
12
9
  export * from './request.js';
13
- export * from './router.js';
14
10
  export * from './serialization.js';
15
- export * from './session_pool/index.js';
16
11
  export * from './storages/index.js';
17
12
  export * from './memory-storage/index.js';
18
13
  export { ArgumentValidationError, validators } from './validators.js';
19
- export * from './cookie_utils.js';
20
- export * from './http.js';
21
14
  export * from './recoverable_state.js';
22
15
  export type { StorageBackend } from '@crawlee/types';
16
+ export { EnqueueStrategy } from '@crawlee/utils';
package/index.js CHANGED
@@ -1,23 +1,17 @@
1
1
  export * from './debug.js';
2
2
  export * from './errors.js';
3
- export * from './autoscaling/index.js';
4
3
  export * from './configuration.js';
5
4
  export * from './service_locator.js';
6
- export * from './crawlers/index.js';
7
- export * from './enqueue_links/index.js';
8
5
  export * from './events/index.js';
9
6
  export * from './log.js';
10
7
  export * from './owned_or_injected.js';
11
8
  export * from './proxy_configuration.js';
12
9
  export * from './request.js';
13
- export * from './router.js';
14
10
  export * from './serialization.js';
15
- export * from './session_pool/index.js';
16
11
  export * from './storages/index.js';
17
12
  export * from './memory-storage/index.js';
18
13
  // Not `export *`: the rest of the module re-exports `@crawlee/utils/internal` symbols, which carry no
19
14
  // semver guarantees and must not reach the public surface. Internal consumers import them directly.
20
15
  export { ArgumentValidationError, validators } from './validators.js';
21
- export * from './cookie_utils.js';
22
- export * from './http.js';
23
16
  export * from './recoverable_state.js';
17
+ export { EnqueueStrategy } from '@crawlee/utils';
package/internal.d.ts ADDED
@@ -0,0 +1,8 @@
1
+ export * from './iterables.js';
2
+ export * from './storages/batched_adds.js';
3
+ export { joinRequestSourceStatuses } from './storages/request_loader.js';
4
+ export * from './system-info/cpu-info.js';
5
+ export * from './system-info/memory-info.js';
6
+ export * from './system-info/ps-tree.js';
7
+ export * from './system-info/runtime.js';
8
+ export * from './url.js';
package/internal.js ADDED
@@ -0,0 +1,9 @@
1
+ // Not part of the public API: internals that other Crawlee packages need but that carry no semver guarantees.
2
+ export * from './iterables.js';
3
+ export * from './storages/batched_adds.js';
4
+ export { joinRequestSourceStatuses } from './storages/request_loader.js';
5
+ export * from './system-info/cpu-info.js';
6
+ export * from './system-info/memory-info.js';
7
+ export * from './system-info/ps-tree.js';
8
+ export * from './system-info/runtime.js';
9
+ export * from './url.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crawlee/core",
3
- "version": "4.0.0-beta.170",
3
+ "version": "4.0.0-beta.171",
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"
@@ -8,6 +8,7 @@
8
8
  "type": "module",
9
9
  "exports": {
10
10
  ".": "./index.js",
11
+ "./internal": "./internal.js",
11
12
  "./package.json": "./package.json"
12
13
  },
13
14
  "keywords": [
@@ -52,10 +53,10 @@
52
53
  "@apify/log": "^3.0.1",
53
54
  "@apify/timeout": "^1.0.1",
54
55
  "@apify/utilities": "^3.0.1",
55
- "@crawlee/fs-storage": "4.0.0-beta.170",
56
- "@crawlee/http-client": "4.0.0-beta.170",
57
- "@crawlee/types": "4.0.0-beta.170",
58
- "@crawlee/utils": "4.0.0-beta.170",
56
+ "@crawlee/fs-storage": "4.0.0-beta.171",
57
+ "@crawlee/http-client": "4.0.0-beta.171",
58
+ "@crawlee/types": "4.0.0-beta.171",
59
+ "@crawlee/utils": "4.0.0-beta.171",
59
60
  "@sapphire/async-queue": "^1.5.5",
60
61
  "@standard-schema/spec": "^1.0.0",
61
62
  "@vladfrangu/async_event_emitter": "^2.4.6",
@@ -63,10 +64,7 @@
63
64
  "csv-stringify": "^6.5.2",
64
65
  "json5": "^2.2.3",
65
66
  "mime-types": "^3.0.1",
66
- "minimatch": "^10.0.1",
67
67
  "stream-json": "^1.9.1",
68
- "tldts": "^7.0.6",
69
- "tough-cookie": "^6.0.0",
70
68
  "tslib": "^2.8.1",
71
69
  "type-fest": "^4.41.0",
72
70
  "zod": "^4.5.4"
@@ -78,5 +76,5 @@
78
76
  }
79
77
  }
80
78
  },
81
- "gitHead": "86e1c891da983125e9e18f1a2327fbcf5e0f5fc2"
79
+ "gitHead": "e4367913045aa04189285719c9bd6912591d34bc"
82
80
  }
package/request.d.ts CHANGED
@@ -1,7 +1,9 @@
1
1
  import type { BinaryLike } from 'node:crypto';
2
2
  import type { AllowedHttpMethods, Dictionary } from '@crawlee/types';
3
- import type { EnqueueStrategyOption } from './enqueue_links/enqueue_links.js';
4
- import type { SkippedRequestReason } from './enqueue_links/shared.js';
3
+ import type { EnqueueStrategy } from '@crawlee/utils';
4
+ /** The `strategy` option accepted by {@link ExtractLinksOptions} and {@link EnqueueUrlsOptions}. */
5
+ export type EnqueueStrategyOption = EnqueueStrategy | 'all' | 'same-domain' | 'same-hostname' | 'same-origin';
6
+ export type SkippedRequestReason = 'robotsTxt' | 'limit' | 'enqueueLimit' | 'filters' | 'transform' | 'redirect' | 'depth';
5
7
  export declare enum RequestState {
6
8
  UNPROCESSED = 0,
7
9
  BEFORE_NAV = 1,
@@ -9,6 +9,4 @@ export * from './storage_instance_manager.js';
9
9
  export * from './storage_stats.js';
10
10
  export * from './utils.js';
11
11
  export * from './transaction.js';
12
- export * from './sitemap_request_loader.js';
13
12
  export * from './request_manager_tandem.js';
14
- export * from './throttling_request_manager.js';
package/storages/index.js CHANGED
@@ -7,6 +7,4 @@ export * from './storage_instance_manager.js';
7
7
  export * from './storage_stats.js';
8
8
  export * from './utils.js';
9
9
  export * from './transaction.js';
10
- export * from './sitemap_request_loader.js';
11
10
  export * from './request_manager_tandem.js';
12
- export * from './throttling_request_manager.js';
@@ -1,196 +0,0 @@
1
- import type { ConcurrencyConsumer, IConcurrencySystem } from './concurrency_system.js';
2
- import type { CrawleeLogger } from '../log.js';
3
- /**
4
- * The two predicates that steer a task loop: *is there work ready?* and *are we done?* These are the parts of the loop
5
- * a caller legitimately overrides, as opposed to the task itself (`runTaskFunction`), which the loop's driver owns.
6
- */
7
- export interface TaskLoopPredicates {
8
- /**
9
- * A function that indicates whether `runTaskFunction` should be called.
10
- * This function is called every time there is free capacity for a new task and it should
11
- * indicate whether it should start a new task or not by resolving to either `true` or `false`.
12
- * Besides its obvious use, it is also useful for task throttling to save resources.
13
- */
14
- isTaskReadyFunction?: () => Promise<boolean>;
15
- /**
16
- * A function that is called only when there are no tasks to be processed.
17
- * If it resolves to `true` then the run finishes. Being called only
18
- * when there are no tasks being processed means that as long as `isTaskReadyFunction()`
19
- * keeps resolving to `true`, `isFinishedFunction()` will never be called.
20
- */
21
- isFinishedFunction?: () => Promise<boolean>;
22
- }
23
- export interface TaskLoopOptions extends TaskLoopPredicates {
24
- /**
25
- * How often the pool should check if a new task is ready, in seconds.
26
- * @default 0.5
27
- */
28
- maybeRunIntervalSecs?: number;
29
- }
30
- /** @internal */
31
- export interface AutoscaledPoolOptions extends TaskLoopOptions {
32
- /**
33
- * The governor that decides whether there is free compute for one more task. Typically a
34
- * {@link ConcurrencySystem}, but any {@link IConcurrencySystem} works. Share a single instance across
35
- * multiple pools (and therefore multiple crawlers) to cap their *combined* concurrency against one budget.
36
- *
37
- * All concurrency/scaling/snapshotter configuration lives on the governor — the pool only owns the task loop and
38
- * its cadence.
39
- */
40
- concurrencySystem: IConcurrencySystem;
41
- /**
42
- * Who this pool is, presented to the governor on every capacity query and booking so that a shared one can tell
43
- * several pools apart. Worth naming meaningfully — a governor that allocates per consumer reports this `id`.
44
- */
45
- consumer: ConcurrencyConsumer;
46
- /**
47
- * A function that performs an asynchronous resource-intensive task.
48
- * The function must either be labeled `async` or return a promise.
49
- */
50
- runTaskFunction?: () => Promise<unknown>;
51
- /**
52
- * Timeout in which the `runTaskFunction` needs to finish, given in seconds.
53
- * @default 0
54
- */
55
- taskTimeoutSecs?: number;
56
- log?: CrawleeLogger;
57
- }
58
- /**
59
- * Manages a pool of asynchronous resource-intensive tasks that are executed in parallel.
60
- * The pool only starts new tasks while its {@link IConcurrencySystem|concurrency system} reports free capacity —
61
- * that governor is what monitors CPU, memory and event loop load and autoscales the concurrency budget.
62
- *
63
- * Before running the pool, you need to implement the following three functions:
64
- * {@link AutoscaledPoolOptions.runTaskFunction|`runTaskFunction`},
65
- * {@link TaskLoopPredicates.isTaskReadyFunction|`isTaskReadyFunction`} and
66
- * {@link TaskLoopPredicates.isFinishedFunction|`isFinishedFunction`}.
67
- *
68
- * The auto-scaled pool is started by calling the {@link AutoscaledPool.run} function.
69
- * The pool periodically queries `isTaskReadyFunction` for more tasks, managing optimal concurrency, until the function
70
- * resolves to `false`. The pool then queries `isFinishedFunction`. If it resolves to `true`, the run finishes after all
71
- * running tasks complete. If it resolves to `false`, it assumes there will be more tasks available later and keeps
72
- * periodically querying for tasks.
73
- * If any of the tasks throws then the {@link AutoscaledPool.run} function rejects the promise with an error.
74
- *
75
- * The pool evaluates whether it should start a new task every time one of the tasks finishes
76
- * and also in the interval set by the `options.maybeRunIntervalSecs` parameter.
77
- *
78
- * **Example usage:**
79
- *
80
- * ```javascript
81
- * const concurrencySystem = new ConcurrencySystem({ maxConcurrency: 50 });
82
- * await concurrencySystem.start();
83
- *
84
- * const pool = new AutoscaledPool({
85
- * concurrencySystem,
86
- * consumer: { id: 'my-pool' },
87
- * runTaskFunction: async () => {
88
- * // Run some resource-intensive asynchronous operation here.
89
- * },
90
- * isTaskReadyFunction: async () => {
91
- * // Tell the pool whether more tasks are ready to be processed.
92
- * // Return true or false
93
- * },
94
- * isFinishedFunction: async () => {
95
- * // Tell the pool whether it should finish
96
- * // or wait for more tasks to become available.
97
- * // Return true or false
98
- * }
99
- * });
100
- *
101
- * try {
102
- * await pool.run();
103
- * } finally {
104
- * await concurrencySystem.stop();
105
- * }
106
- * ```
107
- *
108
- * @internal
109
- */
110
- export declare class AutoscaledPool {
111
- #private;
112
- constructor(options: AutoscaledPoolOptions);
113
- /**
114
- * The governor backing this pool, as supplied to the constructor — exposed as the read-only
115
- * {@link IConcurrencySystem} contract.
116
- *
117
- * This and the two getters below are telemetry only: concurrency is configured and tuned on the concrete
118
- * {@link ConcurrencySystem} its owner holds, never through the pool.
119
- */
120
- get system(): IConcurrencySystem;
121
- /** The estimated number of parallel tasks the governor can currently support. */
122
- get desiredConcurrency(): number;
123
- /**
124
- * The number of parallel tasks currently booked against the governor. When it is shared, this counts every
125
- * borrowing pool's tasks, not just this one's.
126
- */
127
- get currentConcurrency(): number;
128
- /**
129
- * Runs the auto-scaled pool. Returns a promise that gets resolved or rejected once
130
- * all the tasks are finished or one of them fails.
131
- *
132
- * Throws if the {@link IConcurrencySystem|concurrency system} it borrows was never started — the pool assumes
133
- * a running governor and cannot start one it does not own.
134
- */
135
- run(): Promise<void>;
136
- /**
137
- * Aborts the run of the auto-scaled pool and destroys it. The promise returned from
138
- * the {@link AutoscaledPool.run} function will immediately resolve, no more new tasks
139
- * will be spawned and all running tasks will be left in their current state.
140
- *
141
- * Due to the nature of the tasks, auto-scaled pool cannot reliably guarantee abortion
142
- * of all the running tasks, therefore, no abortion is attempted and some of the tasks
143
- * may finish, while others may not. Essentially, auto-scaled pool doesn't care about
144
- * their state after the invocation of `.abort()`, but that does not mean that some
145
- * parts of their asynchronous chains of commands will not execute.
146
- */
147
- abort(): Promise<void>;
148
- /**
149
- * Prevents the auto-scaled pool from starting new tasks, but allows the running ones to finish
150
- * (unlike abort, which terminates them). Used together with {@link AutoscaledPool.resume}
151
- *
152
- * The function's promise will resolve once all running tasks have completed and the pool
153
- * is effectively idle. If the `timeoutSecs` argument is provided, the promise will reject
154
- * with a timeout error after the `timeoutSecs` seconds.
155
- *
156
- * The promise returned from the {@link AutoscaledPool.run} function will not resolve
157
- * when `.pause()` is invoked (unlike abort, which resolves it).
158
- *
159
- * > *NOTE:* Pausing the pool does not suspend the (possibly shared) {@link ConcurrencySystem} — its
160
- * autoscaling and resource monitoring keep running, since other pools borrowing it may still be active. To silence
161
- * it during a long pause, its owner can `stop()` and `start()` it again.
162
- */
163
- pause(timeoutSecs?: number): Promise<void>;
164
- /**
165
- * Resumes the operation of the autoscaled-pool by allowing more tasks to be run.
166
- * Used together with {@link AutoscaledPool.pause}
167
- *
168
- * Tasks will automatically start running again in `options.maybeRunIntervalSecs`.
169
- */
170
- resume(): void;
171
- /**
172
- * Explicitly check the queue for new tasks. The AutoscaledPool checks the queue for new tasks periodically,
173
- * every `maybeRunIntervalSecs` seconds. If you want to trigger the processing immediately, use this method.
174
- */
175
- notify(): Promise<void>;
176
- /**
177
- * Starts a new task
178
- * if the number of running tasks (current concurrency) is lower than desired concurrency
179
- * and the system is not currently overloaded
180
- * and `isTaskReadyFunction()` returns true.
181
- *
182
- * It doesn't allow multiple concurrent runs of this method.
183
- */
184
- private maybeRunTask;
185
- /**
186
- * If there are no running tasks and `isFinishedFunction()` returns true then closes
187
- * the pool and resolves the pool's promise returned by the run() method.
188
- *
189
- * It doesn't allow multiple concurrent runs of this method.
190
- */
191
- private maybeFinish;
192
- /**
193
- * Cleans up resources.
194
- */
195
- private destroy;
196
- }