@crawlee/core 4.0.0-beta.28 → 4.0.0-beta.280
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 +15 -15
- package/byte-utils.d.ts +17 -0
- package/byte-utils.js +42 -0
- package/configuration.d.ts +75 -167
- package/configuration.js +164 -140
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/errors.d.ts +40 -19
- package/errors.js +52 -30
- package/events/{event_manager.d.ts → event-manager.d.ts} +29 -6
- package/events/{event_manager.js → event-manager.js} +10 -9
- package/events/index.d.ts +3 -3
- package/events/index.js +2 -3
- package/events/{local_event_manager.d.ts → local-event-manager.d.ts} +3 -10
- package/events/local-event-manager.js +101 -0
- package/events/system-info.d.ts +38 -0
- package/events/system-info.js +1 -0
- package/index.d.ts +9 -13
- package/index.js +10 -12
- package/internal.d.ts +8 -0
- package/internal.js +9 -0
- package/iterables.d.ts +79 -0
- package/iterables.js +134 -0
- package/log.d.ts +77 -1
- package/log.js +134 -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 +43 -0
- package/memory-storage/memory-storage.js +158 -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 +35 -0
- package/memory-storage/resource-clients/dataset.js +108 -0
- package/memory-storage/resource-clients/key-value-store.d.ts +54 -0
- package/memory-storage/resource-clients/key-value-store.js +179 -0
- package/memory-storage/resource-clients/request-queue.d.ts +55 -0
- package/memory-storage/resource-clients/request-queue.js +413 -0
- package/memory-storage/utils.d.ts +16 -0
- package/memory-storage/utils.js +41 -0
- package/owned-or-injected.d.ts +58 -0
- package/owned-or-injected.js +98 -0
- package/package.json +23 -23
- package/proxy-configuration.d.ts +118 -0
- package/proxy-configuration.js +141 -0
- package/recoverable-state.d.ts +177 -0
- package/recoverable-state.js +268 -0
- package/request.d.ts +48 -101
- package/request.js +139 -249
- package/serialization.d.ts +0 -1
- package/serialization.js +18 -18
- package/{service_locator.d.ts → service-locator.d.ts} +66 -37
- package/service-locator.js +255 -0
- package/storages/batched-adds.d.ts +39 -0
- package/storages/batched-adds.js +81 -0
- package/storages/dataset.d.ts +105 -58
- package/storages/dataset.js +292 -151
- package/storages/index.d.ts +11 -12
- package/storages/index.js +7 -12
- package/storages/key-value-store-codec.d.ts +32 -0
- package/storages/key-value-store-codec.js +108 -0
- package/storages/{key_value_store.d.ts → key-value-store.d.ts} +169 -72
- package/storages/key-value-store.js +767 -0
- package/storages/request-dedup-cache.d.ts +20 -0
- package/storages/request-dedup-cache.js +48 -0
- package/storages/{request_list.d.ts → request-list.d.ts} +32 -171
- package/storages/{request_list.js → request-list.js} +276 -253
- package/storages/request-loader.d.ts +127 -0
- package/storages/request-loader.js +34 -0
- package/storages/request-manager-tandem.d.ts +82 -0
- package/storages/request-manager-tandem.js +200 -0
- package/storages/request-manager.d.ts +119 -0
- package/storages/request-manager.js +1 -0
- package/storages/{request_provider.d.ts → request-queue.d.ts} +127 -161
- package/storages/request-queue.js +871 -0
- package/storages/storage-instance-manager.d.ts +86 -0
- package/storages/storage-instance-manager.js +256 -0
- package/storages/storage-stats.d.ts +48 -0
- package/storages/storage-stats.js +29 -0
- package/storages/transaction.d.ts +270 -0
- package/storages/transaction.js +296 -0
- package/storages/utils.d.ts +59 -11
- package/storages/utils.js +76 -17
- 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 +0 -6
- package/typedefs.js +0 -1
- package/url.d.ts +9 -0
- package/url.js +11 -0
- package/validators.d.ts +23 -18
- package/validators.js +14 -18
- package/autoscaling/autoscaled_pool.d.ts +0 -298
- package/autoscaling/autoscaled_pool.d.ts.map +0 -1
- package/autoscaling/autoscaled_pool.js +0 -527
- package/autoscaling/autoscaled_pool.js.map +0 -1
- package/autoscaling/index.d.ts +0 -4
- package/autoscaling/index.d.ts.map +0 -1
- package/autoscaling/index.js +0 -4
- package/autoscaling/index.js.map +0 -1
- package/autoscaling/snapshotter.d.ts +0 -179
- package/autoscaling/snapshotter.d.ts.map +0 -1
- package/autoscaling/snapshotter.js +0 -279
- package/autoscaling/snapshotter.js.map +0 -1
- package/autoscaling/system_status.d.ts +0 -178
- package/autoscaling/system_status.d.ts.map +0 -1
- package/autoscaling/system_status.js +0 -168
- 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 +0 -43
- package/cookie_utils.d.ts.map +0 -1
- package/cookie_utils.js +0 -111
- package/cookie_utils.js.map +0 -1
- package/crawlers/context_pipeline.d.ts +0 -61
- package/crawlers/context_pipeline.d.ts.map +0 -1
- package/crawlers/context_pipeline.js +0 -99
- package/crawlers/context_pipeline.js.map +0 -1
- package/crawlers/crawler_commons.d.ts +0 -191
- package/crawlers/crawler_commons.d.ts.map +0 -1
- package/crawlers/crawler_commons.js +0 -108
- package/crawlers/crawler_commons.js.map +0 -1
- package/crawlers/crawler_utils.d.ts +0 -10
- package/crawlers/crawler_utils.d.ts.map +0 -1
- package/crawlers/crawler_utils.js +0 -12
- package/crawlers/crawler_utils.js.map +0 -1
- package/crawlers/error_snapshotter.d.ts +0 -60
- package/crawlers/error_snapshotter.d.ts.map +0 -1
- package/crawlers/error_snapshotter.js +0 -118
- package/crawlers/error_snapshotter.js.map +0 -1
- package/crawlers/error_tracker.d.ts +0 -55
- package/crawlers/error_tracker.d.ts.map +0 -1
- package/crawlers/error_tracker.js +0 -309
- package/crawlers/error_tracker.js.map +0 -1
- package/crawlers/index.d.ts +0 -7
- package/crawlers/index.d.ts.map +0 -1
- package/crawlers/index.js +0 -7
- package/crawlers/index.js.map +0 -1
- package/crawlers/internals/types.d.ts +0 -8
- package/crawlers/internals/types.d.ts.map +0 -1
- package/crawlers/internals/types.js +0 -2
- package/crawlers/internals/types.js.map +0 -1
- package/crawlers/statistics.d.ts +0 -204
- package/crawlers/statistics.d.ts.map +0 -1
- package/crawlers/statistics.js +0 -350
- package/crawlers/statistics.js.map +0 -1
- package/enqueue_links/enqueue_links.d.ts +0 -254
- package/enqueue_links/enqueue_links.d.ts.map +0 -1
- package/enqueue_links/enqueue_links.js +0 -268
- package/enqueue_links/enqueue_links.js.map +0 -1
- package/enqueue_links/index.d.ts +0 -3
- package/enqueue_links/index.d.ts.map +0 -1
- package/enqueue_links/index.js +0 -3
- package/enqueue_links/index.js.map +0 -1
- package/enqueue_links/shared.d.ts +0 -84
- package/enqueue_links/shared.d.ts.map +0 -1
- package/enqueue_links/shared.js +0 -219
- 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 +0 -93
- package/events/local_event_manager.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 +0 -169
- package/proxy_configuration.d.ts.map +0 -1
- package/proxy_configuration.js +0 -247
- package/proxy_configuration.js.map +0 -1
- package/recoverable_state.d.ts +0 -122
- package/recoverable_state.d.ts.map +0 -1
- package/recoverable_state.js +0 -138
- package/recoverable_state.js.map +0 -1
- package/request.d.ts.map +0 -1
- package/request.js.map +0 -1
- package/router.d.ts +0 -134
- package/router.d.ts.map +0 -1
- package/router.js +0 -164
- package/router.js.map +0 -1
- package/serialization.d.ts.map +0 -1
- package/serialization.js.map +0 -1
- package/service_locator.d.ts.map +0 -1
- package/service_locator.js +0 -252
- package/service_locator.js.map +0 -1
- package/session_pool/consts.d.ts +0 -4
- package/session_pool/consts.d.ts.map +0 -1
- package/session_pool/consts.js +0 -4
- package/session_pool/consts.js.map +0 -1
- package/session_pool/errors.d.ts +0 -8
- package/session_pool/errors.d.ts.map +0 -1
- package/session_pool/errors.js +0 -12
- 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 +0 -6
- package/session_pool/index.d.ts.map +0 -1
- package/session_pool/index.js +0 -6
- package/session_pool/index.js.map +0 -1
- package/session_pool/session.d.ts +0 -186
- package/session_pool/session.d.ts.map +0 -1
- package/session_pool/session.js +0 -278
- package/session_pool/session.js.map +0 -1
- package/session_pool/session_pool.d.ts +0 -256
- package/session_pool/session_pool.d.ts.map +0 -1
- package/session_pool/session_pool.js +0 -386
- package/session_pool/session_pool.js.map +0 -1
- package/storages/access_checking.d.ts +0 -13
- package/storages/access_checking.d.ts.map +0 -1
- package/storages/access_checking.js +0 -14
- 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 +0 -513
- 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_list_adapter.d.ts +0 -58
- package/storages/request_list_adapter.d.ts.map +0 -1
- package/storages/request_list_adapter.js +0 -81
- package/storages/request_list_adapter.js.map +0 -1
- package/storages/request_manager_tandem.d.ts +0 -68
- package/storages/request_manager_tandem.d.ts.map +0 -1
- package/storages/request_manager_tandem.js +0 -124
- package/storages/request_manager_tandem.js.map +0 -1
- package/storages/request_provider.d.ts.map +0 -1
- package/storages/request_provider.js +0 -592
- package/storages/request_provider.js.map +0 -1
- package/storages/request_queue.d.ts +0 -128
- package/storages/request_queue.d.ts.map +0 -1
- package/storages/request_queue.js +0 -320
- 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 -437
- package/storages/request_queue_v2.js.map +0 -1
- package/storages/sitemap_request_list.d.ts +0 -245
- package/storages/sitemap_request_list.d.ts.map +0 -1
- package/storages/sitemap_request_list.js +0 -431
- package/storages/sitemap_request_list.js.map +0 -1
- package/storages/storage_manager.d.ts +0 -60
- package/storages/storage_manager.d.ts.map +0 -1
- package/storages/storage_manager.js +0 -95
- package/storages/storage_manager.js.map +0 -1
- package/storages/utils.d.ts.map +0 -1
- package/storages/utils.js.map +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
package/errors.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { inspectValue } from './debug.js';
|
|
1
2
|
/**
|
|
2
3
|
* Errors of `NonRetryableError` type will never be retried by the crawler.
|
|
3
4
|
*/
|
|
@@ -9,49 +10,71 @@ export class NonRetryableError extends Error {
|
|
|
9
10
|
*/
|
|
10
11
|
export class CriticalError extends NonRetryableError {
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
function formatIssues(issues) {
|
|
14
|
+
return issues
|
|
15
|
+
.map((issue) => {
|
|
16
|
+
const path = (issue.path ?? [])
|
|
17
|
+
.map((segment) => (typeof segment === 'object' ? segment.key : segment))
|
|
18
|
+
.join('.');
|
|
19
|
+
return `- ${path ? `${path}: ` : ''}${issue.message}`;
|
|
20
|
+
})
|
|
21
|
+
.join('\n');
|
|
16
22
|
}
|
|
17
23
|
/**
|
|
18
|
-
*
|
|
24
|
+
* Thrown when a request's `userData` does not match the {@link RouteSchemas|Standard Schema} registered for its label.
|
|
19
25
|
*
|
|
20
|
-
*
|
|
26
|
+
* As the `userData` does not change between attempts, this error is non-retryable.
|
|
21
27
|
*/
|
|
22
|
-
export class
|
|
23
|
-
|
|
24
|
-
|
|
28
|
+
export class RequestValidationError extends NonRetryableError {
|
|
29
|
+
label;
|
|
30
|
+
issues;
|
|
31
|
+
constructor(label, issues) {
|
|
32
|
+
super(`Request userData for label '${String(label)}' failed schema validation:\n${formatIssues(issues)}`);
|
|
33
|
+
this.label = label;
|
|
34
|
+
this.issues = issues;
|
|
25
35
|
}
|
|
26
36
|
}
|
|
27
37
|
/**
|
|
28
|
-
*
|
|
38
|
+
* Thrown by {@link RecoverableState} when a persisted state record does not match its `stateSchema`.
|
|
29
39
|
*
|
|
30
|
-
*
|
|
40
|
+
* Whether a corrupt record should abort the run or be discarded in favour of the defaults depends on what the
|
|
41
|
+
* state is for, so {@link RecoverableState.initialize} always throws and leaves the choice to the caller.
|
|
31
42
|
*/
|
|
32
|
-
export class
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
export class StateValidationError extends Error {
|
|
44
|
+
persistStateKey;
|
|
45
|
+
issues;
|
|
46
|
+
constructor(persistStateKey, issues) {
|
|
47
|
+
super(`State persisted under key '${persistStateKey}' failed schema validation:\n${formatIssues(issues)}`);
|
|
48
|
+
this.persistStateKey = persistStateKey;
|
|
49
|
+
this.issues = issues;
|
|
35
50
|
}
|
|
36
51
|
}
|
|
37
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Errors of `SessionError` type retire the session associated with the request and trigger a regular retry.
|
|
54
|
+
*
|
|
55
|
+
* The retry counts towards the `maxRequestRetries` limit, just like any other error.
|
|
56
|
+
*/
|
|
57
|
+
export class SessionError extends Error {
|
|
38
58
|
constructor(message) {
|
|
39
|
-
super(`
|
|
59
|
+
super(`Detected a session error, retiring session... ${message ? `\n${message}` : ''}`);
|
|
40
60
|
}
|
|
41
61
|
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
export class ContextPipelineCleanupError extends CriticalError {
|
|
48
|
-
constructor(error, options) {
|
|
49
|
-
super(undefined, { cause: error, ...options });
|
|
50
|
-
}
|
|
62
|
+
/**
|
|
63
|
+
* A {@link SessionError} for a session that finished without being blocked, e.g. by reaching its
|
|
64
|
+
* `maxUsageCount` or `maxAgeSecs`. A plain `SessionError` means the session was blocked.
|
|
65
|
+
*/
|
|
66
|
+
export class SessionRetiredError extends SessionError {
|
|
51
67
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Wraps the failure of a callback registered with {@link StorageTransaction.afterCommit|`afterCommit`}
|
|
70
|
+
* that ran after the request's writes had already been committed.
|
|
71
|
+
*
|
|
72
|
+
* Non-retryable by nature: the writes are durable, so re-running the request handler would duplicate
|
|
73
|
+
* them. A callback that throws a `NonRetryableError` of its own is left alone.
|
|
74
|
+
*/
|
|
75
|
+
export class AfterCommitError extends NonRetryableError {
|
|
76
|
+
constructor(cause) {
|
|
77
|
+
super(cause instanceof Error ? cause.message : String(cause), { cause });
|
|
55
78
|
}
|
|
56
79
|
}
|
|
57
80
|
/**
|
|
@@ -60,7 +83,6 @@ export class RequestHandlerError extends Error {
|
|
|
60
83
|
export class ServiceConflictError extends Error {
|
|
61
84
|
constructor(serviceName, newValue, existingValue) {
|
|
62
85
|
super(`Service ${serviceName} is already in use. ` +
|
|
63
|
-
`Existing value: ${existingValue}, attempted new value: ${newValue}.`);
|
|
86
|
+
`Existing value: ${inspectValue(existingValue)}, attempted new value: ${inspectValue(newValue)}.`);
|
|
64
87
|
}
|
|
65
88
|
}
|
|
66
|
-
//# sourceMappingURL=errors.js.map
|
|
@@ -4,25 +4,49 @@ export interface EventManagerOptions {
|
|
|
4
4
|
/** Interval between emitted `persistState` events in milliseconds. */
|
|
5
5
|
persistStateIntervalMillis: number;
|
|
6
6
|
}
|
|
7
|
-
export declare
|
|
7
|
+
export declare enum EventType {
|
|
8
8
|
PERSIST_STATE = "persistState",
|
|
9
9
|
SYSTEM_INFO = "systemInfo",
|
|
10
10
|
MIGRATING = "migrating",
|
|
11
11
|
ABORTING = "aborting",
|
|
12
|
-
EXIT = "exit"
|
|
12
|
+
EXIT = "exit",
|
|
13
|
+
STATUS_MESSAGE = "statusMessage"
|
|
14
|
+
}
|
|
15
|
+
export type EventTypeName = EventType | 'systemInfo' | 'persistState' | 'migrating' | 'aborting' | 'exit' | 'statusMessage';
|
|
16
|
+
/**
|
|
17
|
+
* Payload emitted with the {@link EventType.STATUS_MESSAGE|`statusMessage`} event.
|
|
18
|
+
*
|
|
19
|
+
* The crawler broadcasts these whenever it wants to report its progress (e.g. periodically, or on
|
|
20
|
+
* start/finish). Consumers such as the Apify SDK can listen for the event and propagate the message
|
|
21
|
+
* to the platform. This keeps the crawler decoupled from any specific status-reporting backend.
|
|
22
|
+
*/
|
|
23
|
+
export interface EventStatusMessageData {
|
|
24
|
+
/**
|
|
25
|
+
* Identifies the crawler that emitted the message.
|
|
26
|
+
*
|
|
27
|
+
* Either the user-provided `id` from the crawler options, or a randomly generated one.
|
|
28
|
+
* Since a single event manager may be shared by multiple crawlers, consumers can use this
|
|
29
|
+
* to attribute the message to a specific crawler instance.
|
|
30
|
+
*/
|
|
31
|
+
crawlerId: string;
|
|
32
|
+
/** The human-readable status message. */
|
|
33
|
+
message: string;
|
|
34
|
+
/** Whether this is the final status message of the run. */
|
|
35
|
+
isStatusMessageTerminal?: boolean;
|
|
36
|
+
/** The log level the message was logged with. */
|
|
37
|
+
level?: 'DEBUG' | 'INFO' | 'WARNING' | 'ERROR';
|
|
13
38
|
}
|
|
14
|
-
export type EventTypeName = EventType | 'systemInfo' | 'persistState' | 'migrating' | 'aborting' | 'exit';
|
|
15
39
|
interface Intervals {
|
|
16
40
|
persistState?: BetterIntervalID;
|
|
17
41
|
systemInfo?: BetterIntervalID;
|
|
18
42
|
}
|
|
19
43
|
export declare abstract class EventManager {
|
|
44
|
+
#private;
|
|
20
45
|
protected events: AsyncEventEmitter<{}>;
|
|
21
46
|
protected initialized: boolean;
|
|
22
47
|
protected intervals: Intervals;
|
|
23
48
|
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
24
|
-
protected log: import("@
|
|
25
|
-
private persistStateIntervalMillis;
|
|
49
|
+
protected log: import("@crawlee/types").CrawleeLogger;
|
|
26
50
|
constructor(options: EventManagerOptions);
|
|
27
51
|
/**
|
|
28
52
|
* Initializes the event manager by starting the `persistState` event interval.
|
|
@@ -52,4 +76,3 @@ export declare abstract class EventManager {
|
|
|
52
76
|
waitForAllListenersToComplete(): Promise<boolean>;
|
|
53
77
|
}
|
|
54
78
|
export {};
|
|
55
|
-
//# sourceMappingURL=event_manager.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
|
|
2
|
-
import log from '@apify/log';
|
|
3
2
|
import { betterClearInterval, betterSetInterval } from '@apify/utilities';
|
|
3
|
+
import { serviceLocator } from '../service-locator.js';
|
|
4
4
|
export var EventType;
|
|
5
5
|
(function (EventType) {
|
|
6
6
|
EventType["PERSIST_STATE"] = "persistState";
|
|
@@ -8,16 +8,18 @@ export var EventType;
|
|
|
8
8
|
EventType["MIGRATING"] = "migrating";
|
|
9
9
|
EventType["ABORTING"] = "aborting";
|
|
10
10
|
EventType["EXIT"] = "exit";
|
|
11
|
+
EventType["STATUS_MESSAGE"] = "statusMessage";
|
|
11
12
|
})(EventType || (EventType = {}));
|
|
12
13
|
export class EventManager {
|
|
13
14
|
events = new AsyncEventEmitter();
|
|
14
15
|
initialized = false;
|
|
15
16
|
intervals = {};
|
|
16
|
-
log =
|
|
17
|
-
persistStateIntervalMillis;
|
|
17
|
+
log = serviceLocator.getLogger().child({ prefix: 'Events' });
|
|
18
|
+
#persistStateIntervalMillis;
|
|
18
19
|
constructor(options) {
|
|
19
|
-
this
|
|
20
|
-
|
|
20
|
+
this.#persistStateIntervalMillis = options.persistStateIntervalMillis;
|
|
21
|
+
// One MIGRATING listener per RequestQueue, and ThrottlingRequestManager opens one per domain.
|
|
22
|
+
this.events.setMaxListeners(150);
|
|
21
23
|
}
|
|
22
24
|
/**
|
|
23
25
|
* Initializes the event manager by starting the `persistState` event interval.
|
|
@@ -28,9 +30,9 @@ export class EventManager {
|
|
|
28
30
|
return;
|
|
29
31
|
}
|
|
30
32
|
this.intervals.persistState = betterSetInterval((intervalCallback) => {
|
|
31
|
-
this.emit(
|
|
33
|
+
this.emit(EventType.PERSIST_STATE, { isMigrating: false });
|
|
32
34
|
intervalCallback();
|
|
33
|
-
}, this
|
|
35
|
+
}, this.#persistStateIntervalMillis);
|
|
34
36
|
this.initialized = true;
|
|
35
37
|
}
|
|
36
38
|
/**
|
|
@@ -44,7 +46,7 @@ export class EventManager {
|
|
|
44
46
|
betterClearInterval(this.intervals.persistState);
|
|
45
47
|
this.initialized = false;
|
|
46
48
|
// Emit final PERSIST_STATE event
|
|
47
|
-
this.emit(
|
|
49
|
+
this.emit(EventType.PERSIST_STATE, { isMigrating: false });
|
|
48
50
|
// Wait for PERSIST_STATE to process
|
|
49
51
|
await this.waitForAllListenersToComplete();
|
|
50
52
|
}
|
|
@@ -84,4 +86,3 @@ export class EventManager {
|
|
|
84
86
|
return this.events.waitForAllListenersToComplete();
|
|
85
87
|
}
|
|
86
88
|
}
|
|
87
|
-
//# sourceMappingURL=event_manager.js.map
|
package/events/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
|
|
1
|
+
export * from './event-manager.js';
|
|
2
|
+
export * from './local-event-manager.js';
|
|
3
|
+
export type * from './system-info.js';
|
package/events/index.js
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
export * from './event-manager.js';
|
|
2
|
+
export * from './local-event-manager.js';
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { Configuration } from '../configuration.js';
|
|
2
|
-
import { EventManager, type EventManagerOptions } from './
|
|
2
|
+
import { EventManager, type EventManagerOptions } from './event-manager.js';
|
|
3
3
|
export interface LocalEventManagerOptions extends EventManagerOptions {
|
|
4
4
|
/** Interval between emitted `systemInfo` events in milliseconds. */
|
|
5
5
|
systemInfoIntervalMillis: number;
|
|
6
6
|
}
|
|
7
7
|
export declare class LocalEventManager extends EventManager {
|
|
8
|
-
private
|
|
8
|
+
#private;
|
|
9
9
|
constructor(options: LocalEventManagerOptions);
|
|
10
10
|
/**
|
|
11
11
|
* Creates a new `LocalEventManager` based on the provided `Configuration`.
|
|
12
12
|
* Uses the global configuration from the service locator if none is provided.
|
|
13
13
|
*/
|
|
14
|
-
static
|
|
14
|
+
static fromConfiguration(configuration?: Configuration): LocalEventManager;
|
|
15
15
|
/**
|
|
16
16
|
* Initializes the EventManager and sets up periodic `systemInfo` events.
|
|
17
17
|
* This is automatically called at the beginning of `crawler.run()`.
|
|
@@ -29,11 +29,4 @@ export declare class LocalEventManager extends EventManager {
|
|
|
29
29
|
* @internal
|
|
30
30
|
*/
|
|
31
31
|
isContainerizedWrapper(): Promise<boolean>;
|
|
32
|
-
/**
|
|
33
|
-
* Creates a SystemInfo object based on local metrics.
|
|
34
|
-
*/
|
|
35
|
-
private createSystemInfo;
|
|
36
|
-
private createCpuInfo;
|
|
37
|
-
private createMemoryInfo;
|
|
38
32
|
}
|
|
39
|
-
//# sourceMappingURL=local_event_manager.d.ts.map
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { betterClearInterval, betterSetInterval } from '@apify/utilities';
|
|
2
|
+
import { serviceLocator } from '../service-locator.js';
|
|
3
|
+
import { EventManager, EventType } from './event-manager.js';
|
|
4
|
+
export class LocalEventManager extends EventManager {
|
|
5
|
+
#systemInfoIntervalMillis;
|
|
6
|
+
constructor(options) {
|
|
7
|
+
super(options);
|
|
8
|
+
this.#systemInfoIntervalMillis = options.systemInfoIntervalMillis;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Creates a new `LocalEventManager` based on the provided `Configuration`.
|
|
12
|
+
* Uses the global configuration from the service locator if none is provided.
|
|
13
|
+
*/
|
|
14
|
+
static fromConfiguration(configuration) {
|
|
15
|
+
const resolvedConfiguration = configuration ?? serviceLocator.getConfiguration();
|
|
16
|
+
return new LocalEventManager({
|
|
17
|
+
persistStateIntervalMillis: resolvedConfiguration.persistStateIntervalMillis,
|
|
18
|
+
systemInfoIntervalMillis: resolvedConfiguration.systemInfoIntervalMillis,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Initializes the EventManager and sets up periodic `systemInfo` events.
|
|
23
|
+
* This is automatically called at the beginning of `crawler.run()`.
|
|
24
|
+
*/
|
|
25
|
+
async init() {
|
|
26
|
+
if (this.initialized) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
await super.init();
|
|
30
|
+
this.emitSystemInfoEvent = this.emitSystemInfoEvent.bind(this);
|
|
31
|
+
this.intervals.systemInfo = betterSetInterval(this.emitSystemInfoEvent.bind(this), this.#systemInfoIntervalMillis);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* @inheritDoc
|
|
35
|
+
*/
|
|
36
|
+
async close() {
|
|
37
|
+
if (!this.initialized) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
await super.close();
|
|
41
|
+
betterClearInterval(this.intervals.systemInfo);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
async emitSystemInfoEvent(intervalCallback) {
|
|
47
|
+
const info = await this.#createSystemInfo({
|
|
48
|
+
maxUsedCpuRatio: serviceLocator.getConfiguration().maxUsedCpuRatio,
|
|
49
|
+
});
|
|
50
|
+
this.events.emit(EventType.SYSTEM_INFO, info);
|
|
51
|
+
intervalCallback();
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
async isContainerizedWrapper() {
|
|
57
|
+
const { isContainerized } = await import('../system-info/runtime.js');
|
|
58
|
+
return serviceLocator.getConfiguration().containerized ?? (await isContainerized());
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Creates a SystemInfo object based on local metrics.
|
|
62
|
+
*/
|
|
63
|
+
async #createSystemInfo(options) {
|
|
64
|
+
return {
|
|
65
|
+
createdAt: new Date(),
|
|
66
|
+
...(await this.#createCpuInfo(options)),
|
|
67
|
+
...(await this.#createMemoryInfo()),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
async #createCpuInfo(options) {
|
|
71
|
+
const { getCurrentCpuTicksV2 } = await import('../system-info/cpu-info.js');
|
|
72
|
+
const usedCpuRatio = await getCurrentCpuTicksV2({
|
|
73
|
+
containerized: await this.isContainerizedWrapper(),
|
|
74
|
+
logger: serviceLocator.getLogger(),
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
cpuCurrentUsage: usedCpuRatio * 100,
|
|
78
|
+
isCpuOverloaded: usedCpuRatio > options.maxUsedCpuRatio,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async #createMemoryInfo() {
|
|
82
|
+
try {
|
|
83
|
+
const memInfo = await this.#getMemoryInfo();
|
|
84
|
+
return {
|
|
85
|
+
memTotalBytes: memInfo.totalBytes,
|
|
86
|
+
memCurrentBytes: memInfo.mainProcessBytes + memInfo.childProcessesBytes,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
catch (err) {
|
|
90
|
+
this.log.exception(err, 'Memory snapshot failed.');
|
|
91
|
+
return {};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async #getMemoryInfo() {
|
|
95
|
+
const { getMemoryInfo } = await import('../system-info/memory-info.js');
|
|
96
|
+
return getMemoryInfo({
|
|
97
|
+
containerized: await this.isContainerizedWrapper(),
|
|
98
|
+
logger: serviceLocator.getLogger(),
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/index.d.ts
CHANGED
|
@@ -1,20 +1,16 @@
|
|
|
1
|
+
export * from './debug.js';
|
|
1
2
|
export * from './errors.js';
|
|
2
|
-
export * from './autoscaling/index.js';
|
|
3
3
|
export * from './configuration.js';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './crawlers/index.js';
|
|
6
|
-
export * from './enqueue_links/index.js';
|
|
4
|
+
export * from './service-locator.js';
|
|
7
5
|
export * from './events/index.js';
|
|
8
6
|
export * from './log.js';
|
|
9
|
-
export * from './
|
|
7
|
+
export * from './owned-or-injected.js';
|
|
8
|
+
export * from './proxy-configuration.js';
|
|
10
9
|
export * from './request.js';
|
|
11
|
-
export * from './router.js';
|
|
12
10
|
export * from './serialization.js';
|
|
13
|
-
export * from './session_pool/index.js';
|
|
14
11
|
export * from './storages/index.js';
|
|
15
|
-
export * from './
|
|
16
|
-
export
|
|
17
|
-
export * from './
|
|
18
|
-
export {
|
|
19
|
-
export {
|
|
20
|
-
//# sourceMappingURL=index.d.ts.map
|
|
12
|
+
export * from './memory-storage/index.js';
|
|
13
|
+
export { ArgumentValidationError, validators } from './validators.js';
|
|
14
|
+
export * from './recoverable-state.js';
|
|
15
|
+
export type { StorageBackend } from '@crawlee/types';
|
|
16
|
+
export { EnqueueStrategy } from '@crawlee/utils';
|
package/index.js
CHANGED
|
@@ -1,19 +1,17 @@
|
|
|
1
|
+
export * from './debug.js';
|
|
1
2
|
export * from './errors.js';
|
|
2
|
-
export * from './autoscaling/index.js';
|
|
3
3
|
export * from './configuration.js';
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './crawlers/index.js';
|
|
6
|
-
export * from './enqueue_links/index.js';
|
|
4
|
+
export * from './service-locator.js';
|
|
7
5
|
export * from './events/index.js';
|
|
8
6
|
export * from './log.js';
|
|
9
|
-
export * from './
|
|
7
|
+
export * from './owned-or-injected.js';
|
|
8
|
+
export * from './proxy-configuration.js';
|
|
10
9
|
export * from './request.js';
|
|
11
|
-
export * from './router.js';
|
|
12
10
|
export * from './serialization.js';
|
|
13
|
-
export * from './session_pool/index.js';
|
|
14
11
|
export * from './storages/index.js';
|
|
15
|
-
export * from './
|
|
16
|
-
export
|
|
17
|
-
|
|
18
|
-
export {
|
|
19
|
-
|
|
12
|
+
export * from './memory-storage/index.js';
|
|
13
|
+
// Not `export *`: the rest of the module re-exports `@crawlee/utils/internal` symbols, which carry no
|
|
14
|
+
// semver guarantees and must not reach the public surface. Internal consumers import them directly.
|
|
15
|
+
export { ArgumentValidationError, validators } from './validators.js';
|
|
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/iterables.d.ts
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts any iterable or async iterable to an async iterable.
|
|
3
|
+
* @internal
|
|
4
|
+
*
|
|
5
|
+
* @yields Each item from the input iterable
|
|
6
|
+
*
|
|
7
|
+
* **Example usage:**
|
|
8
|
+
* ```ts
|
|
9
|
+
* const syncArray = [1, 2, 3];
|
|
10
|
+
* for await (const item of asyncifyIterable(syncArray)) {
|
|
11
|
+
* console.log(item); // 1, 2, 3
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function asyncifyIterable<T>(iterable: Iterable<T> | AsyncIterable<T>): AsyncIterable<T>;
|
|
16
|
+
/**
|
|
17
|
+
* Lazily splits the input async iterable into chunks of specified size.
|
|
18
|
+
* The last chunk may contain fewer items if the total number of items
|
|
19
|
+
* is not evenly divisible by the chunk size.
|
|
20
|
+
* @internal
|
|
21
|
+
*
|
|
22
|
+
* @yields Arrays of items, each containing up to chunkSize items
|
|
23
|
+
*
|
|
24
|
+
* **Example usage:**
|
|
25
|
+
* ```ts
|
|
26
|
+
* const numbers = async function* () {
|
|
27
|
+
* for (let i = 1; i <= 10; i++) yield i;
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* for await (const chunk of chunkedAsyncIterable(numbers(), 3)) {
|
|
31
|
+
* console.log(chunk); // [1, 2, 3], [4, 5, 6], [7, 8, 9], [10]
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function chunkedAsyncIterable<T>(iterable: AsyncIterable<T> | Iterable<T>, chunkSize: number | (() => number)): AsyncIterable<T[]>;
|
|
36
|
+
/**
|
|
37
|
+
* An async iterator that also supports peeking at the next value without consuming it.
|
|
38
|
+
* Extends both AsyncIterator and AsyncIterable interfaces.
|
|
39
|
+
* @internal
|
|
40
|
+
*/
|
|
41
|
+
export interface PeekableAsyncIterator<T> extends AsyncIterator<T>, AsyncIterable<T> {
|
|
42
|
+
/**
|
|
43
|
+
* Peeks at the next value without consuming it from the iterator.
|
|
44
|
+
* Subsequent calls to peek() will return the same value until next() is called.
|
|
45
|
+
*
|
|
46
|
+
* @returns Promise that resolves to the next value, or undefined if the iterator is exhausted
|
|
47
|
+
*/
|
|
48
|
+
peek(): Promise<T | undefined>;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* An async iterable that yields peekable async iterators.
|
|
52
|
+
* @internal
|
|
53
|
+
*/
|
|
54
|
+
export interface PeekableAsyncIterable<T> extends AsyncIterable<T> {
|
|
55
|
+
[Symbol.asyncIterator](): PeekableAsyncIterator<T>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Wraps an async iterable to provide peek functionality, allowing you to look at
|
|
59
|
+
* the next value without consuming it from the iterator.
|
|
60
|
+
* @internal
|
|
61
|
+
*
|
|
62
|
+
* @param iterable - The async iterable to make peekable
|
|
63
|
+
*
|
|
64
|
+
* **Example usage:**
|
|
65
|
+
* ```ts
|
|
66
|
+
* const numbers = async function* () {
|
|
67
|
+
* yield 1; yield 2; yield 3;
|
|
68
|
+
* };
|
|
69
|
+
*
|
|
70
|
+
* const peekable = peekableAsyncIterable(numbers());
|
|
71
|
+
* const iterator = peekable[Symbol.asyncIterator]();
|
|
72
|
+
*
|
|
73
|
+
* console.log(await iterator.peek()); // 1 (doesn't consume)
|
|
74
|
+
* console.log(await iterator.peek()); // 1 (still doesn't consume)
|
|
75
|
+
* console.log(await iterator.next()); // { value: 1, done: false } (now consumed)
|
|
76
|
+
* console.log(await iterator.peek()); // 2 (next value)
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
export declare function peekableAsyncIterable<T>(iterable: AsyncIterable<T> | Iterable<T>): PeekableAsyncIterable<T>;
|