apify 4.0.0-beta.131 → 4.0.0-beta.132
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.
|
@@ -10,16 +10,16 @@ import { Configuration } from './configuration.js';
|
|
|
10
10
|
* **Example usage:**
|
|
11
11
|
*
|
|
12
12
|
* ```javascript
|
|
13
|
-
* Actor.on('
|
|
13
|
+
* Actor.on('systemInfo', (data) => {
|
|
14
14
|
* if (data.isCpuOverloaded) console.log('Oh no, the CPU is overloaded!');
|
|
15
15
|
* });
|
|
16
16
|
* ```
|
|
17
17
|
*
|
|
18
18
|
* The following events are emitted:
|
|
19
19
|
*
|
|
20
|
-
* - `
|
|
21
|
-
* The event is emitted approximately every second
|
|
22
|
-
*
|
|
20
|
+
* - `systemInfo`: `{ "cpuCurrentUsage": Number, "isCpuOverloaded": Boolean, "memCurrentBytes": Number, ... }`
|
|
21
|
+
* The event is emitted approximately every second and it describes the CPU and memory usage of the Actor.
|
|
22
|
+
* `isCpuOverloaded` indicates whether the Actor is using the maximum of available CPU resources.
|
|
23
23
|
* If that's the case, the Actor should not add more workload.
|
|
24
24
|
* For example, this event is used by the {@link AutoscaledPool} class.
|
|
25
25
|
* - `migrating`: `void`
|
|
@@ -39,6 +39,10 @@ import { Configuration } from './configuration.js';
|
|
|
39
39
|
* Note that the `persistState` event is provided merely for user convenience,
|
|
40
40
|
* you can achieve the same effect using `setInterval()` and listening for the `migrating` event.
|
|
41
41
|
*
|
|
42
|
+
* Messages with any other name are not emitted. This includes the deprecated `cpuInfo` event, which the platform
|
|
43
|
+
* sends next to `systemInfo` for backward compatibility. Registering a `cpuInfo` listener logs a warning.
|
|
44
|
+
* Unknown names are logged at the debug level.
|
|
45
|
+
*
|
|
42
46
|
* The connection to the platform events websocket is re-established after it drops, unless it was closed
|
|
43
47
|
* with a code signalling a permanent condition (e.g. `1008` for an unknown run ID).
|
|
44
48
|
*/
|
|
@@ -50,6 +54,7 @@ export declare class PlatformEventManager extends EventManager {
|
|
|
50
54
|
* user code can neither remove them with `off()` nor see them in `listeners()`.
|
|
51
55
|
*/
|
|
52
56
|
constructor(configuration?: Configuration, internalListeners?: Partial<Record<EventTypeName, (...args: any[]) => unknown>>);
|
|
57
|
+
on(event: EventTypeName, listener: (...args: any[]) => any): void;
|
|
53
58
|
emit(event: EventTypeName, ...args: unknown[]): void;
|
|
54
59
|
waitForAllListenersToComplete(): Promise<boolean>;
|
|
55
60
|
/**
|
|
@@ -15,6 +15,13 @@ const NON_RETRYABLE_CLOSE_CODES = new Set([1002, 1003, 1007, 1008, 1010]);
|
|
|
15
15
|
const CLEAN_CLOSE_CODES = new Set([1000, 1001]);
|
|
16
16
|
/** How long a connection must stay open to count as healthy, after which a drop reconnects without backoff. */
|
|
17
17
|
const HEALTHY_CONNECTION_MIN_DURATION_MILLIS = 1000;
|
|
18
|
+
/** Names of the platform events that are emitted to listeners. Messages with any other name are dropped. */
|
|
19
|
+
const PLATFORM_EVENT_NAMES = new Set([
|
|
20
|
+
ACTOR_EVENT_NAMES.SYSTEM_INFO,
|
|
21
|
+
ACTOR_EVENT_NAMES.MIGRATING,
|
|
22
|
+
ACTOR_EVENT_NAMES.ABORTING,
|
|
23
|
+
ACTOR_EVENT_NAMES.PERSIST_STATE,
|
|
24
|
+
]);
|
|
18
25
|
/**
|
|
19
26
|
* Delays between reconnection attempts, mirroring the Python `websockets` library
|
|
20
27
|
* (see RFC 6455, section 7.2.3): a random initial delay, then exponential growth up to a cap.
|
|
@@ -38,16 +45,16 @@ function* backoffDelays() {
|
|
|
38
45
|
* **Example usage:**
|
|
39
46
|
*
|
|
40
47
|
* ```javascript
|
|
41
|
-
* Actor.on('
|
|
48
|
+
* Actor.on('systemInfo', (data) => {
|
|
42
49
|
* if (data.isCpuOverloaded) console.log('Oh no, the CPU is overloaded!');
|
|
43
50
|
* });
|
|
44
51
|
* ```
|
|
45
52
|
*
|
|
46
53
|
* The following events are emitted:
|
|
47
54
|
*
|
|
48
|
-
* - `
|
|
49
|
-
* The event is emitted approximately every second
|
|
50
|
-
*
|
|
55
|
+
* - `systemInfo`: `{ "cpuCurrentUsage": Number, "isCpuOverloaded": Boolean, "memCurrentBytes": Number, ... }`
|
|
56
|
+
* The event is emitted approximately every second and it describes the CPU and memory usage of the Actor.
|
|
57
|
+
* `isCpuOverloaded` indicates whether the Actor is using the maximum of available CPU resources.
|
|
51
58
|
* If that's the case, the Actor should not add more workload.
|
|
52
59
|
* For example, this event is used by the {@link AutoscaledPool} class.
|
|
53
60
|
* - `migrating`: `void`
|
|
@@ -67,6 +74,10 @@ function* backoffDelays() {
|
|
|
67
74
|
* Note that the `persistState` event is provided merely for user convenience,
|
|
68
75
|
* you can achieve the same effect using `setInterval()` and listening for the `migrating` event.
|
|
69
76
|
*
|
|
77
|
+
* Messages with any other name are not emitted. This includes the deprecated `cpuInfo` event, which the platform
|
|
78
|
+
* sends next to `systemInfo` for backward compatibility. Registering a `cpuInfo` listener logs a warning.
|
|
79
|
+
* Unknown names are logged at the debug level.
|
|
80
|
+
*
|
|
70
81
|
* The connection to the platform events websocket is re-established after it drops, unless it was closed
|
|
71
82
|
* with a code signalling a permanent condition (e.g. `1008` for an unknown run ID).
|
|
72
83
|
*/
|
|
@@ -92,6 +103,13 @@ export class PlatformEventManager extends EventManager {
|
|
|
92
103
|
this.configuration = configuration;
|
|
93
104
|
this.#internalListeners = internalListeners;
|
|
94
105
|
}
|
|
106
|
+
on(event, listener) {
|
|
107
|
+
if (event === ACTOR_EVENT_NAMES.CPU_INFO) {
|
|
108
|
+
this.log.warning('The "cpuInfo" event is deprecated and never emitted. ' +
|
|
109
|
+
'Listen to "systemInfo" instead, which has the same "isCpuOverloaded" field.');
|
|
110
|
+
}
|
|
111
|
+
super.on(event, listener);
|
|
112
|
+
}
|
|
95
113
|
emit(event, ...args) {
|
|
96
114
|
super.emit(event, ...args);
|
|
97
115
|
const listener = this.#internalListeners[event];
|
|
@@ -183,6 +201,12 @@ export class PlatformEventManager extends EventManager {
|
|
|
183
201
|
return;
|
|
184
202
|
try {
|
|
185
203
|
const { name, data } = JSON.parse(String(message));
|
|
204
|
+
if (name === ACTOR_EVENT_NAMES.CPU_INFO)
|
|
205
|
+
return;
|
|
206
|
+
if (!PLATFORM_EVENT_NAMES.has(name)) {
|
|
207
|
+
this.log.debug('Unknown platform event received', { name, data });
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
186
210
|
this.emit(name, data);
|
|
187
211
|
if (name === ACTOR_EVENT_NAMES.MIGRATING) {
|
|
188
212
|
betterClearInterval(this.intervals.persistState); // Don't send any other persist state event.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "apify",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.132",
|
|
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"
|