@crawlee/core 4.0.0-beta.26 → 4.0.0-beta.261
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 +77 -235
- package/configuration.js +159 -227
- package/debug.d.ts +36 -0
- package/debug.js +70 -0
- package/errors.d.ts +45 -18
- package/errors.js +58 -27
- package/events/event-manager.d.ts +78 -0
- package/events/{event_manager.js → event-manager.js} +12 -13
- package/events/index.d.ts +3 -3
- package/events/index.js +2 -3
- package/events/local-event-manager.d.ts +32 -0
- 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 -12
- package/index.js +10 -11
- 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 -93
- package/request.js +139 -232
- package/serialization.d.ts +0 -1
- package/serialization.js +18 -18
- package/service-locator.d.ts +168 -0
- package/service-locator.js +255 -0
- package/storages/batched-adds.d.ts +39 -0
- package/storages/batched-adds.js +78 -0
- package/storages/dataset.d.ts +105 -58
- package/storages/dataset.js +292 -150
- 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} +33 -173
- package/storages/{request_list.js → request-list.js} +276 -255
- package/storages/request-loader.d.ts +127 -0
- package/storages/request-loader.js +36 -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} +128 -159
- 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 -16
- 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 -300
- package/autoscaling/autoscaled_pool.d.ts.map +0 -1
- package/autoscaling/autoscaled_pool.js +0 -533
- 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 -189
- package/autoscaling/snapshotter.d.ts.map +0 -1
- package/autoscaling/snapshotter.js +0 -285
- package/autoscaling/snapshotter.js.map +0 -1
- package/autoscaling/system_status.d.ts +0 -181
- package/autoscaling/system_status.d.ts.map +0 -1
- package/autoscaling/system_status.js +0 -169
- 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 -213
- package/crawlers/statistics.d.ts.map +0 -1
- package/crawlers/statistics.js +0 -349
- package/crawlers/statistics.js.map +0 -1
- package/enqueue_links/enqueue_links.d.ts +0 -249
- package/enqueue_links/enqueue_links.d.ts.map +0 -1
- package/enqueue_links/enqueue_links.js +0 -269
- 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 -73
- package/enqueue_links/shared.d.ts.map +0 -1
- package/enqueue_links/shared.js +0 -212
- 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 +0 -52
- 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 +0 -27
- package/events/local_event_manager.d.ts.map +0 -1
- package/events/local_event_manager.js +0 -75
- 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 -123
- package/recoverable_state.d.ts.map +0 -1
- package/recoverable_state.js +0 -140
- 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/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 -258
- package/session_pool/session_pool.d.ts.map +0 -1
- package/session_pool/session_pool.js +0 -387
- 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 -512
- 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 -591
- 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 -438
- package/storages/request_queue_v2.js.map +0 -1
- package/storages/sitemap_request_list.d.ts +0 -250
- 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 -62
- package/storages/storage_manager.d.ts.map +0 -1
- package/storages/storage_manager.js +0 -105
- 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
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { spawn } from 'node:child_process';
|
|
2
|
+
import * as readline from 'node:readline';
|
|
3
|
+
/**
|
|
4
|
+
* Returns a promise that resolves with an array of ProcessInfo objects representing
|
|
5
|
+
* the children of the given PID.
|
|
6
|
+
*
|
|
7
|
+
* @param pid - The PID (number or string) for which to list child processes.
|
|
8
|
+
* @param includeRoot - Optional flag. When true, include the process with the given PID if found.
|
|
9
|
+
* Defaults to false.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export async function psTree(pid, includeRoot = false) {
|
|
13
|
+
return new Promise((resolve, reject) => {
|
|
14
|
+
if (typeof pid === 'number') {
|
|
15
|
+
pid = pid.toString();
|
|
16
|
+
}
|
|
17
|
+
let processLister;
|
|
18
|
+
if (process.platform === 'win32') {
|
|
19
|
+
processLister = spawn('powershell', [
|
|
20
|
+
'-NoProfile',
|
|
21
|
+
'-Command',
|
|
22
|
+
'Get-CimInstance Win32_Process | Format-Table ProcessId,ParentProcessId,WorkingSetSize,Name',
|
|
23
|
+
]);
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
processLister = spawn('ps', ['-A', '-o', 'ppid,pid,stat,rss,comm']);
|
|
27
|
+
}
|
|
28
|
+
processLister.on('error', reject);
|
|
29
|
+
if (!processLister.stdout) {
|
|
30
|
+
reject(new Error('Child process stdout is null'));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
// Create a readline interface to process stdout line-by-line.
|
|
34
|
+
const rl = readline.createInterface({
|
|
35
|
+
input: processLister.stdout,
|
|
36
|
+
});
|
|
37
|
+
const rows = [];
|
|
38
|
+
let headers = null;
|
|
39
|
+
rl.on('line', (line) => {
|
|
40
|
+
const trimmed = line.trim();
|
|
41
|
+
if (trimmed === '') {
|
|
42
|
+
return; // Skip empty lines.
|
|
43
|
+
}
|
|
44
|
+
// When headers have been set, skip a dashed separator line.
|
|
45
|
+
const fields = trimmed.split(/\s+/);
|
|
46
|
+
if (headers !== null && fields.every((field) => /^-+$/.test(field))) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
// The first nonempty line is assumed to be the header row.
|
|
50
|
+
if (!headers) {
|
|
51
|
+
headers = fields.map(normalizeHeader);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Copy the fields into an array to process.
|
|
55
|
+
const columns = fields.slice();
|
|
56
|
+
// Build the process row object.
|
|
57
|
+
const row = {};
|
|
58
|
+
const hdrs = headers.slice();
|
|
59
|
+
// For all headers except the last one, assign one column per header.
|
|
60
|
+
// The last header gets all remaining columns joined (in case the command name contains spaces).
|
|
61
|
+
for (const [index, header] of hdrs.entries()) {
|
|
62
|
+
let value;
|
|
63
|
+
if (index === hdrs.length - 1) {
|
|
64
|
+
value = columns.join(' ');
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
value = columns.shift();
|
|
68
|
+
}
|
|
69
|
+
if (header === 'RSS') {
|
|
70
|
+
row[header] = Number.parseInt(value, 10);
|
|
71
|
+
if (process.platform !== 'win32') {
|
|
72
|
+
// On Unix like systems, convert RSS (in KB) to bytes.
|
|
73
|
+
row[header] *= 1024;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
row[header] = value;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
// On Windows, add STAT with a null value for compatibility.
|
|
81
|
+
if (process.platform === 'win32') {
|
|
82
|
+
row.STAT = null;
|
|
83
|
+
}
|
|
84
|
+
rows.push(row);
|
|
85
|
+
});
|
|
86
|
+
rl.on('close', () => {
|
|
87
|
+
const parents = {};
|
|
88
|
+
const children = [];
|
|
89
|
+
// Seed with the provided PID.
|
|
90
|
+
parents[pid] = true;
|
|
91
|
+
// Build the list of child processes.
|
|
92
|
+
rows.forEach((proc) => {
|
|
93
|
+
// Skip the 'ps' or 'powershell' commands used by psTree to query the processes
|
|
94
|
+
if (proc.COMMAND === 'ps' || proc.COMMAND === 'powershell.exe') {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
if (parents[proc.PPID]) {
|
|
98
|
+
parents[proc.PID] = true;
|
|
99
|
+
children.push(proc);
|
|
100
|
+
}
|
|
101
|
+
else if (includeRoot && pid === proc.PID) {
|
|
102
|
+
children.push(proc);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
resolve(children);
|
|
106
|
+
});
|
|
107
|
+
// Also listen for errors on the stdout stream.
|
|
108
|
+
processLister.stdout.on('error', reject);
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Normalizes the header names so that the rest of the code can work uniformly.
|
|
113
|
+
*
|
|
114
|
+
* On non‑Windows systems, we only adjust "COMM" to "COMMAND" (e.g. on macOS).
|
|
115
|
+
* On Windows, the headers from Get-CimInstance + Format-Table are:
|
|
116
|
+
*
|
|
117
|
+
* ProcessId, ParentProcessId, WorkingSetSize, Name
|
|
118
|
+
*
|
|
119
|
+
* which are mapped to:
|
|
120
|
+
*
|
|
121
|
+
* PID, PPID, RSS, COMMAND
|
|
122
|
+
*/
|
|
123
|
+
function normalizeHeader(str) {
|
|
124
|
+
if (process.platform !== 'win32') {
|
|
125
|
+
// macOS may output "COMM" instead of "COMMAND"
|
|
126
|
+
if (str === 'COMM')
|
|
127
|
+
return 'COMMAND';
|
|
128
|
+
return str;
|
|
129
|
+
}
|
|
130
|
+
switch (str) {
|
|
131
|
+
case 'Name':
|
|
132
|
+
return 'COMMAND';
|
|
133
|
+
case 'ParentProcessId':
|
|
134
|
+
return 'PPID';
|
|
135
|
+
case 'ProcessId':
|
|
136
|
+
return 'PID';
|
|
137
|
+
case 'Status':
|
|
138
|
+
return 'STAT';
|
|
139
|
+
case 'WorkingSetSize':
|
|
140
|
+
return 'RSS';
|
|
141
|
+
default:
|
|
142
|
+
throw new Error(`Unknown process listing header: ${str}`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a `Promise` that resolves to true if the code is running in a Docker container.
|
|
3
|
+
*/
|
|
4
|
+
export declare function isDocker(forceReset?: boolean): Promise<boolean>;
|
|
5
|
+
/**
|
|
6
|
+
* Detects if crawlee is running in a containerized environment.
|
|
7
|
+
*/
|
|
8
|
+
export declare function isContainerized(): Promise<boolean>;
|
|
9
|
+
export declare function isLambda(): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* gets the cgroup version by checking for a file at /sys/fs/cgroup/memory
|
|
12
|
+
* @returns "V1" or "V2" for the version of cgroup or null if cgroup is not found.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getCgroupsVersion(forceReset?: boolean): Promise<"V1" | "V2" | null>;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import fs from 'node:fs/promises';
|
|
2
|
+
let isDockerPromiseCache;
|
|
3
|
+
async function createIsDockerPromise() {
|
|
4
|
+
const promise1 = fs
|
|
5
|
+
.stat('/.dockerenv')
|
|
6
|
+
.then(() => true)
|
|
7
|
+
.catch(() => false);
|
|
8
|
+
const promise2 = fs
|
|
9
|
+
.readFile('/proc/self/cgroup', 'utf8')
|
|
10
|
+
.then((content) => content.includes('docker'))
|
|
11
|
+
.catch(() => false);
|
|
12
|
+
const [result1, result2] = await Promise.all([promise1, promise2]);
|
|
13
|
+
return result1 || result2;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns a `Promise` that resolves to true if the code is running in a Docker container.
|
|
17
|
+
*/
|
|
18
|
+
export async function isDocker(forceReset) {
|
|
19
|
+
// Parameter forceReset is just internal for unit tests.
|
|
20
|
+
if (!isDockerPromiseCache || forceReset)
|
|
21
|
+
isDockerPromiseCache = createIsDockerPromise();
|
|
22
|
+
return isDockerPromiseCache;
|
|
23
|
+
}
|
|
24
|
+
let isContainerizedResult;
|
|
25
|
+
/**
|
|
26
|
+
* Detects if crawlee is running in a containerized environment.
|
|
27
|
+
*/
|
|
28
|
+
export async function isContainerized() {
|
|
29
|
+
// Value is very unlikley to change. Cache the result after the first execution.
|
|
30
|
+
if (isContainerizedResult !== undefined) {
|
|
31
|
+
return isContainerizedResult;
|
|
32
|
+
}
|
|
33
|
+
// return false if running in aws lambda
|
|
34
|
+
if (isLambda()) {
|
|
35
|
+
isContainerizedResult = false;
|
|
36
|
+
return isContainerizedResult;
|
|
37
|
+
}
|
|
38
|
+
const dockerenvCheck = fs
|
|
39
|
+
.stat('/.dockerenv')
|
|
40
|
+
.then(() => true)
|
|
41
|
+
.catch(() => false);
|
|
42
|
+
const cgroupCheck = fs
|
|
43
|
+
.readFile('/proc/self/cgroup', 'utf8')
|
|
44
|
+
.then((content) => content.includes('docker'))
|
|
45
|
+
.catch(() => false);
|
|
46
|
+
const [dockerenvResult, cgroupResult] = await Promise.all([dockerenvCheck, cgroupCheck]);
|
|
47
|
+
isContainerizedResult = dockerenvResult || cgroupResult || !!process.env.KUBERNETES_SERVICE_HOST;
|
|
48
|
+
return isContainerizedResult;
|
|
49
|
+
}
|
|
50
|
+
export function isLambda() {
|
|
51
|
+
return !!process.env.AWS_LAMBDA_FUNCTION_MEMORY_SIZE;
|
|
52
|
+
}
|
|
53
|
+
let cgroupsVersion;
|
|
54
|
+
/**
|
|
55
|
+
* gets the cgroup version by checking for a file at /sys/fs/cgroup/memory
|
|
56
|
+
* @returns "V1" or "V2" for the version of cgroup or null if cgroup is not found.
|
|
57
|
+
*/
|
|
58
|
+
export async function getCgroupsVersion(forceReset) {
|
|
59
|
+
// Parameter forceReset is just internal for unit tests.
|
|
60
|
+
if (cgroupsVersion !== undefined && !forceReset) {
|
|
61
|
+
return cgroupsVersion;
|
|
62
|
+
}
|
|
63
|
+
try {
|
|
64
|
+
// If this directory does not exists, cgroups are not available
|
|
65
|
+
await fs.access('/sys/fs/cgroup/');
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
cgroupsVersion = null;
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
cgroupsVersion = 'V1';
|
|
72
|
+
try {
|
|
73
|
+
// If this directory does not exists, assume the container is using cgroups V2
|
|
74
|
+
await fs.access('/sys/fs/cgroup/memory/');
|
|
75
|
+
}
|
|
76
|
+
catch (e) {
|
|
77
|
+
cgroupsVersion = 'V2';
|
|
78
|
+
}
|
|
79
|
+
return cgroupsVersion;
|
|
80
|
+
}
|
package/typedefs.d.ts
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
1
|
/** @ignore */
|
|
2
|
-
export type Constructor<T = unknown> = new (...args: any[]) => T;
|
|
3
|
-
/** @ignore */
|
|
4
|
-
export type Awaitable<T> = T | PromiseLike<T>;
|
|
5
|
-
/** @ignore */
|
|
6
2
|
export declare function entries<T extends {}>(obj: T): [keyof T, T[keyof T]][];
|
|
7
3
|
/** @ignore */
|
|
8
4
|
export declare function keys<T extends {}>(obj: T): (keyof T)[];
|
|
9
|
-
export { AllowedHttpMethods } from '@crawlee/types';
|
|
10
|
-
//# sourceMappingURL=typedefs.d.ts.map
|
package/typedefs.js
CHANGED
package/url.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canonical form of a hostname: lower-case, punycode, and without the optional root dot.
|
|
3
|
+
*
|
|
4
|
+
* Pass both sides of a hostname comparison through this, so that a domain written as `háčky.cz` still matches the
|
|
5
|
+
* `xn--hky-ela4t.cz` that `URL` reports.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export declare function normalizeHostname(hostname: string): string;
|
package/url.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The canonical form of a hostname: lower-case, punycode, and without the optional root dot.
|
|
3
|
+
*
|
|
4
|
+
* Pass both sides of a hostname comparison through this, so that a domain written as `háčky.cz` still matches the
|
|
5
|
+
* `xn--hky-ela4t.cz` that `URL` reports.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export function normalizeHostname(hostname) {
|
|
10
|
+
return hostname.toLowerCase().replace(/\.$/, '');
|
|
11
|
+
}
|
package/validators.d.ts
CHANGED
|
@@ -1,21 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
export { ArgumentValidationError } from '@crawlee/utils';
|
|
2
|
+
export { parseArgument } from '@crawlee/utils/internal';
|
|
3
|
+
export { schemas } from '@crawlee/utils/internal';
|
|
2
4
|
/** @internal */
|
|
3
5
|
export declare const validators: {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
6
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
7
|
+
browserPage: import("zod").ZodType<import("@crawlee/types").Dictionary, unknown, import("zod/v4/core").$ZodTypeInternals<import("@crawlee/types").Dictionary, unknown>>;
|
|
8
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
9
|
+
proxyConfiguration: import("zod").ZodType<import("@crawlee/types").Dictionary, unknown, import("zod/v4/core").$ZodTypeInternals<import("@crawlee/types").Dictionary, unknown>>;
|
|
10
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
11
|
+
requestList: import("zod").ZodType<import("@crawlee/types").Dictionary, unknown, import("zod/v4/core").$ZodTypeInternals<import("@crawlee/types").Dictionary, unknown>>;
|
|
12
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
13
|
+
requestQueue: import("zod").ZodType<import("@crawlee/types").Dictionary, unknown, import("zod/v4/core").$ZodTypeInternals<import("@crawlee/types").Dictionary, unknown>>;
|
|
14
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
15
|
+
browserPool: import("zod").ZodType<import("@crawlee/types").Dictionary, unknown, import("zod/v4/core").$ZodTypeInternals<import("@crawlee/types").Dictionary, unknown>>;
|
|
16
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
17
|
+
sessionPool: import("zod").ZodType<import("@crawlee/types").Dictionary, unknown, import("zod/v4/core").$ZodTypeInternals<import("@crawlee/types").Dictionary, unknown>>;
|
|
18
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
19
|
+
requestManager: import("zod").ZodType<import("@crawlee/types").Dictionary, unknown, import("zod/v4/core").$ZodTypeInternals<import("@crawlee/types").Dictionary, unknown>>;
|
|
20
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
21
|
+
storageBackend: import("zod").ZodType<import("@crawlee/types").Dictionary, unknown, import("zod/v4/core").$ZodTypeInternals<import("@crawlee/types").Dictionary, unknown>>;
|
|
22
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
23
|
+
logger: import("zod").ZodType<import("@crawlee/types").Dictionary, unknown, import("zod/v4/core").$ZodTypeInternals<import("@crawlee/types").Dictionary, unknown>>;
|
|
24
|
+
// @ts-ignore optional peer dependency or compatibility with es2022
|
|
25
|
+
httpClient: import("zod").ZodInstanceOf<import("@crawlee/http-client").BaseHttpClient>;
|
|
20
26
|
};
|
|
21
|
-
//# sourceMappingURL=validators.d.ts.map
|
package/validators.js
CHANGED
|
@@ -1,22 +1,18 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { schemas } from '@crawlee/utils/internal';
|
|
2
|
+
export { ArgumentValidationError } from '@crawlee/utils';
|
|
3
|
+
export { parseArgument } from '@crawlee/utils/internal';
|
|
4
|
+
export { schemas } from '@crawlee/utils/internal';
|
|
2
5
|
/** @internal */
|
|
3
6
|
export const validators = {
|
|
4
7
|
// Naming it browser page for future proofing with Playwright
|
|
5
|
-
browserPage: (
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
message: (label) => `Expected argument '${label}' to be a RequestList, got something else.`,
|
|
16
|
-
}),
|
|
17
|
-
requestQueue: (value) => ({
|
|
18
|
-
validator: ow.isValid(value, ow.object.hasKeys('fetchNextRequest', 'addRequest')),
|
|
19
|
-
message: (label) => `Expected argument '${label}' to be a RequestQueue, got something else.`,
|
|
20
|
-
}),
|
|
8
|
+
browserPage: schemas.objectWithKeys(['goto', 'evaluate', '$', 'on'], 'Expected a Puppeteer Page, got something else.'),
|
|
9
|
+
proxyConfiguration: schemas.objectWithKeys(['newProxyInfo'], "Expected an object implementing the IProxyConfiguration interface (missing 'newProxyInfo'), got something else."),
|
|
10
|
+
requestList: schemas.objectWithKeys(['fetchNextRequest', 'checkReadiness'], 'Expected a RequestList, got something else.'),
|
|
11
|
+
requestQueue: schemas.objectWithKeys(['fetchNextRequest', 'addRequest'], 'Expected a RequestQueue, got something else.'),
|
|
12
|
+
browserPool: schemas.objectWithKeys(['newPage', 'closePage', 'extractPageState', 'injectPageState'], "Expected an object implementing the IBrowserPool interface (missing one of 'newPage', 'closePage', 'extractPageState', 'injectPageState'), got something else."),
|
|
13
|
+
sessionPool: schemas.objectWithKeys(['getSession'], "Expected an object implementing the ISessionPool interface (missing 'getSession'), got something else."),
|
|
14
|
+
requestManager: schemas.objectWithKeys(['fetchNextRequest', 'addRequest', 'addRequestsBatched'], "Expected an object implementing the IRequestManager interface (missing one of 'fetchNextRequest', 'addRequest', 'addRequestsBatched'), got something else."),
|
|
15
|
+
storageBackend: schemas.objectWithKeys(['createDatasetBackend', 'createKeyValueStoreBackend', 'createRequestQueueBackend'], "Expected an object implementing the StorageBackend interface (missing one of 'createDatasetBackend', 'createKeyValueStoreBackend', 'createRequestQueueBackend'), got something else."),
|
|
16
|
+
logger: schemas.logger,
|
|
17
|
+
httpClient: schemas.httpClient,
|
|
21
18
|
};
|
|
22
|
-
//# sourceMappingURL=validators.js.map
|
|
@@ -1,300 +0,0 @@
|
|
|
1
|
-
import type { Log } from '@apify/log';
|
|
2
|
-
import { Configuration } from '../configuration.js';
|
|
3
|
-
import type { SnapshotterOptions } from './snapshotter.js';
|
|
4
|
-
import type { SystemInfo, SystemStatusOptions } from './system_status.js';
|
|
5
|
-
export interface AutoscaledPoolOptions {
|
|
6
|
-
/**
|
|
7
|
-
* A function that performs an asynchronous resource-intensive task.
|
|
8
|
-
* The function must either be labeled `async` or return a promise.
|
|
9
|
-
*/
|
|
10
|
-
runTaskFunction?: () => Promise<unknown>;
|
|
11
|
-
/**
|
|
12
|
-
* A function that indicates whether `runTaskFunction` should be called.
|
|
13
|
-
* This function is called every time there is free capacity for a new task and it should
|
|
14
|
-
* indicate whether it should start a new task or not by resolving to either `true` or `false`.
|
|
15
|
-
* Besides its obvious use, it is also useful for task throttling to save resources.
|
|
16
|
-
*/
|
|
17
|
-
isTaskReadyFunction?: () => Promise<boolean>;
|
|
18
|
-
/**
|
|
19
|
-
* A function that is called only when there are no tasks to be processed.
|
|
20
|
-
* If it resolves to `true` then the pool's run finishes. Being called only
|
|
21
|
-
* when there are no tasks being processed means that as long as `isTaskReadyFunction()`
|
|
22
|
-
* keeps resolving to `true`, `isFinishedFunction()` will never be called.
|
|
23
|
-
* To abort a run, use the {@link AutoscaledPool.abort} method.
|
|
24
|
-
*/
|
|
25
|
-
isFinishedFunction?: () => Promise<boolean>;
|
|
26
|
-
/**
|
|
27
|
-
* The minimum number of tasks running in parallel.
|
|
28
|
-
*
|
|
29
|
-
* *WARNING:* If you set this value too high with respect to the available system memory and CPU, your code might run extremely slow or crash.
|
|
30
|
-
* If you're not sure, just keep the default value and the concurrency will scale up automatically.
|
|
31
|
-
* @default 1
|
|
32
|
-
*/
|
|
33
|
-
minConcurrency?: number;
|
|
34
|
-
/**
|
|
35
|
-
* The maximum number of tasks running in parallel.
|
|
36
|
-
* @default 200
|
|
37
|
-
*/
|
|
38
|
-
maxConcurrency?: number;
|
|
39
|
-
/**
|
|
40
|
-
* The desired number of tasks that should be running parallel on the start of the pool,
|
|
41
|
-
* if there is a large enough supply of them.
|
|
42
|
-
* By default, it is `minConcurrency`.
|
|
43
|
-
*/
|
|
44
|
-
desiredConcurrency?: number;
|
|
45
|
-
/**
|
|
46
|
-
* Minimum level of desired concurrency to reach before more scaling up is allowed.
|
|
47
|
-
* @default 0.90
|
|
48
|
-
*/
|
|
49
|
-
desiredConcurrencyRatio?: number;
|
|
50
|
-
/**
|
|
51
|
-
* Defines the fractional amount of desired concurrency to be added with each scaling up.
|
|
52
|
-
* The minimum scaling step is one.
|
|
53
|
-
* @default 0.05
|
|
54
|
-
*/
|
|
55
|
-
scaleUpStepRatio?: number;
|
|
56
|
-
/**
|
|
57
|
-
* Defines the amount of desired concurrency to be subtracted with each scaling down.
|
|
58
|
-
* The minimum scaling step is one.
|
|
59
|
-
* @default 0.05
|
|
60
|
-
*/
|
|
61
|
-
scaleDownStepRatio?: number;
|
|
62
|
-
/**
|
|
63
|
-
* Indicates how often the pool should call the `runTaskFunction()` to start a new task, in seconds.
|
|
64
|
-
* This has no effect on starting new tasks immediately after a task completes.
|
|
65
|
-
* @default 0.5
|
|
66
|
-
*/
|
|
67
|
-
maybeRunIntervalSecs?: number;
|
|
68
|
-
/**
|
|
69
|
-
* Specifies a period in which the instance logs its state, in seconds.
|
|
70
|
-
* Set to `null` to disable periodic logging.
|
|
71
|
-
* @default 60
|
|
72
|
-
*/
|
|
73
|
-
loggingIntervalSecs?: number | null;
|
|
74
|
-
/**
|
|
75
|
-
* Defines in seconds how often the pool should attempt to adjust the desired concurrency
|
|
76
|
-
* based on the latest system status. Setting it lower than 1 might have a severe impact on performance.
|
|
77
|
-
* We suggest using a value from 5 to 20.
|
|
78
|
-
* @default 10
|
|
79
|
-
*/
|
|
80
|
-
autoscaleIntervalSecs?: number;
|
|
81
|
-
/**
|
|
82
|
-
* Timeout in which the `runTaskFunction` needs to finish, given in seconds.
|
|
83
|
-
* @default 0
|
|
84
|
-
*/
|
|
85
|
-
taskTimeoutSecs?: number;
|
|
86
|
-
/**
|
|
87
|
-
* Options to be passed down to the {@link Snapshotter} constructor. This is useful for fine-tuning
|
|
88
|
-
* the snapshot intervals and history.
|
|
89
|
-
*/
|
|
90
|
-
snapshotterOptions?: SnapshotterOptions;
|
|
91
|
-
/**
|
|
92
|
-
* Options to be passed down to the {@link SystemStatus} constructor. This is useful for fine-tuning
|
|
93
|
-
* the system status reports. If a custom snapshotter is set in the options, it will be used
|
|
94
|
-
* by the pool.
|
|
95
|
-
*/
|
|
96
|
-
systemStatusOptions?: SystemStatusOptions;
|
|
97
|
-
/**
|
|
98
|
-
* The maximum number of tasks per minute the pool can run.
|
|
99
|
-
* By default, this is set to `Infinity`, but you can pass any positive, non-zero integer.
|
|
100
|
-
*/
|
|
101
|
-
maxTasksPerMinute?: number;
|
|
102
|
-
log?: Log;
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Manages a pool of asynchronous resource-intensive tasks that are executed in parallel.
|
|
106
|
-
* The pool only starts new tasks if there is enough free CPU and memory available
|
|
107
|
-
* and the Javascript event loop is not blocked.
|
|
108
|
-
*
|
|
109
|
-
* The information about the CPU and memory usage is obtained by the {@link Snapshotter} class,
|
|
110
|
-
* which makes regular snapshots of system resources that may be either local
|
|
111
|
-
* or from the Apify cloud infrastructure in case the process is running on the Apify platform.
|
|
112
|
-
* Meaningful data gathered from these snapshots is provided to `AutoscaledPool` by the {@link SystemStatus} class.
|
|
113
|
-
*
|
|
114
|
-
* Before running the pool, you need to implement the following three functions:
|
|
115
|
-
* {@link AutoscaledPoolOptions.runTaskFunction},
|
|
116
|
-
* {@link AutoscaledPoolOptions.isTaskReadyFunction} and
|
|
117
|
-
* {@link AutoscaledPoolOptions.isFinishedFunction}.
|
|
118
|
-
*
|
|
119
|
-
* The auto-scaled pool is started by calling the {@link AutoscaledPool.run} function.
|
|
120
|
-
* The pool periodically queries the {@link AutoscaledPoolOptions.isTaskReadyFunction} function
|
|
121
|
-
* for more tasks, managing optimal concurrency, until the function resolves to `false`. The pool then queries
|
|
122
|
-
* the {@link AutoscaledPoolOptions.isFinishedFunction}. If it resolves to `true`, the run finishes after all running tasks complete.
|
|
123
|
-
* If it resolves to `false`, it assumes there will be more tasks available later and keeps periodically querying for tasks.
|
|
124
|
-
* If any of the tasks throws then the {@link AutoscaledPool.run} function rejects the promise with an error.
|
|
125
|
-
*
|
|
126
|
-
* The pool evaluates whether it should start a new task every time one of the tasks finishes
|
|
127
|
-
* and also in the interval set by the `options.maybeRunIntervalSecs` parameter.
|
|
128
|
-
*
|
|
129
|
-
* **Example usage:**
|
|
130
|
-
*
|
|
131
|
-
* ```javascript
|
|
132
|
-
* const pool = new AutoscaledPool({
|
|
133
|
-
* maxConcurrency: 50,
|
|
134
|
-
* runTaskFunction: async () => {
|
|
135
|
-
* // Run some resource-intensive asynchronous operation here.
|
|
136
|
-
* },
|
|
137
|
-
* isTaskReadyFunction: async () => {
|
|
138
|
-
* // Tell the pool whether more tasks are ready to be processed.
|
|
139
|
-
* // Return true or false
|
|
140
|
-
* },
|
|
141
|
-
* isFinishedFunction: async () => {
|
|
142
|
-
* // Tell the pool whether it should finish
|
|
143
|
-
* // or wait for more tasks to become available.
|
|
144
|
-
* // Return true or false
|
|
145
|
-
* }
|
|
146
|
-
* });
|
|
147
|
-
*
|
|
148
|
-
* await pool.run();
|
|
149
|
-
* ```
|
|
150
|
-
* @category Scaling
|
|
151
|
-
*/
|
|
152
|
-
export declare class AutoscaledPool {
|
|
153
|
-
private readonly config;
|
|
154
|
-
private readonly log;
|
|
155
|
-
private readonly desiredConcurrencyRatio;
|
|
156
|
-
private readonly scaleUpStepRatio;
|
|
157
|
-
private readonly scaleDownStepRatio;
|
|
158
|
-
private readonly maybeRunIntervalMillis;
|
|
159
|
-
private readonly loggingIntervalMillis;
|
|
160
|
-
private readonly autoscaleIntervalMillis;
|
|
161
|
-
private readonly taskTimeoutMillis;
|
|
162
|
-
private readonly runTaskFunction;
|
|
163
|
-
private readonly isFinishedFunction;
|
|
164
|
-
private readonly isTaskReadyFunction;
|
|
165
|
-
private readonly maxTasksPerMinute;
|
|
166
|
-
private _minConcurrency;
|
|
167
|
-
private _maxConcurrency;
|
|
168
|
-
private _desiredConcurrency;
|
|
169
|
-
private _currentConcurrency;
|
|
170
|
-
private isStopped;
|
|
171
|
-
private lastLoggingTime?;
|
|
172
|
-
private resolve;
|
|
173
|
-
private reject;
|
|
174
|
-
private snapshotter;
|
|
175
|
-
private systemStatus;
|
|
176
|
-
private autoscaleInterval;
|
|
177
|
-
private maybeRunInterval;
|
|
178
|
-
private queryingIsTaskReady;
|
|
179
|
-
private queryingIsFinished;
|
|
180
|
-
private tasksDonePerSecondInterval?;
|
|
181
|
-
private _tasksPerMinute;
|
|
182
|
-
constructor(options: AutoscaledPoolOptions, config?: Configuration);
|
|
183
|
-
/**
|
|
184
|
-
* Gets the minimum number of tasks running in parallel.
|
|
185
|
-
*/
|
|
186
|
-
get minConcurrency(): number;
|
|
187
|
-
/**
|
|
188
|
-
* Sets the minimum number of tasks running in parallel.
|
|
189
|
-
*
|
|
190
|
-
* *WARNING:* If you set this value too high with respect to the available system memory and CPU, your code might run extremely slow or crash.
|
|
191
|
-
* If you're not sure, just keep the default value and the concurrency will scale up automatically.
|
|
192
|
-
*/
|
|
193
|
-
set minConcurrency(value: number);
|
|
194
|
-
/**
|
|
195
|
-
* Gets the maximum number of tasks running in parallel.
|
|
196
|
-
*/
|
|
197
|
-
get maxConcurrency(): number;
|
|
198
|
-
/**
|
|
199
|
-
* Sets the maximum number of tasks running in parallel.
|
|
200
|
-
*/
|
|
201
|
-
set maxConcurrency(value: number);
|
|
202
|
-
/**
|
|
203
|
-
* Gets the desired concurrency for the pool,
|
|
204
|
-
* which is an estimated number of parallel tasks that the system can currently support.
|
|
205
|
-
*/
|
|
206
|
-
get desiredConcurrency(): number;
|
|
207
|
-
/**
|
|
208
|
-
* Sets the desired concurrency for the pool, i.e. the number of tasks that should be running
|
|
209
|
-
* in parallel if there's large enough supply of tasks.
|
|
210
|
-
*/
|
|
211
|
-
set desiredConcurrency(value: number);
|
|
212
|
-
/**
|
|
213
|
-
* Gets the number of parallel tasks currently running in the pool.
|
|
214
|
-
*/
|
|
215
|
-
get currentConcurrency(): number;
|
|
216
|
-
/**
|
|
217
|
-
* Runs the auto-scaled pool. Returns a promise that gets resolved or rejected once
|
|
218
|
-
* all the tasks are finished or one of them fails.
|
|
219
|
-
*/
|
|
220
|
-
run(): Promise<void>;
|
|
221
|
-
/**
|
|
222
|
-
* Aborts the run of the auto-scaled pool and destroys it. The promise returned from
|
|
223
|
-
* the {@link AutoscaledPool.run} function will immediately resolve, no more new tasks
|
|
224
|
-
* will be spawned and all running tasks will be left in their current state.
|
|
225
|
-
*
|
|
226
|
-
* Due to the nature of the tasks, auto-scaled pool cannot reliably guarantee abortion
|
|
227
|
-
* of all the running tasks, therefore, no abortion is attempted and some of the tasks
|
|
228
|
-
* may finish, while others may not. Essentially, auto-scaled pool doesn't care about
|
|
229
|
-
* their state after the invocation of `.abort()`, but that does not mean that some
|
|
230
|
-
* parts of their asynchronous chains of commands will not execute.
|
|
231
|
-
*/
|
|
232
|
-
abort(): Promise<void>;
|
|
233
|
-
/**
|
|
234
|
-
* Prevents the auto-scaled pool from starting new tasks, but allows the running ones to finish
|
|
235
|
-
* (unlike abort, which terminates them). Used together with {@link AutoscaledPool.resume}
|
|
236
|
-
*
|
|
237
|
-
* The function's promise will resolve once all running tasks have completed and the pool
|
|
238
|
-
* is effectively idle. If the `timeoutSecs` argument is provided, the promise will reject
|
|
239
|
-
* with a timeout error after the `timeoutSecs` seconds.
|
|
240
|
-
*
|
|
241
|
-
* The promise returned from the {@link AutoscaledPool.run} function will not resolve
|
|
242
|
-
* when `.pause()` is invoked (unlike abort, which resolves it).
|
|
243
|
-
*/
|
|
244
|
-
pause(timeoutSecs?: number): Promise<void>;
|
|
245
|
-
/**
|
|
246
|
-
* Resumes the operation of the autoscaled-pool by allowing more tasks to be run.
|
|
247
|
-
* Used together with {@link AutoscaledPool.pause}
|
|
248
|
-
*
|
|
249
|
-
* Tasks will automatically start running again in `options.maybeRunIntervalSecs`.
|
|
250
|
-
*/
|
|
251
|
-
resume(): void;
|
|
252
|
-
/**
|
|
253
|
-
* Explicitly check the queue for new tasks. The AutoscaledPool checks the queue for new tasks periodically,
|
|
254
|
-
* every `maybeRunIntervalSecs` seconds. If you want to trigger the processing immediately, use this method.
|
|
255
|
-
*/
|
|
256
|
-
notify(): Promise<void>;
|
|
257
|
-
/**
|
|
258
|
-
* Starts a new task
|
|
259
|
-
* if the number of running tasks (current concurrency) is lower than desired concurrency
|
|
260
|
-
* and the system is not currently overloaded
|
|
261
|
-
* and this.isTaskReadyFunction() returns true.
|
|
262
|
-
*
|
|
263
|
-
* It doesn't allow multiple concurrent runs of this method.
|
|
264
|
-
*/
|
|
265
|
-
protected _maybeRunTask(intervalCallback?: () => void): Promise<void>;
|
|
266
|
-
/**
|
|
267
|
-
* Gets called every autoScaleIntervalSecs and evaluates the current system status.
|
|
268
|
-
* If the system IS NOT overloaded and the settings allow it, it scales up.
|
|
269
|
-
* If the system IS overloaded and the settings allow it, it scales down.
|
|
270
|
-
*/
|
|
271
|
-
protected _autoscale(intervalCallback: () => void): void;
|
|
272
|
-
/**
|
|
273
|
-
* Scales the pool up by increasing
|
|
274
|
-
* the desired concurrency by the scaleUpStepRatio.
|
|
275
|
-
*
|
|
276
|
-
* @param systemStatus for logging
|
|
277
|
-
*/
|
|
278
|
-
protected _scaleUp(systemStatus: SystemInfo): void;
|
|
279
|
-
/**
|
|
280
|
-
* Scales the pool down by decreasing
|
|
281
|
-
* the desired concurrency by the scaleDownStepRatio.
|
|
282
|
-
*
|
|
283
|
-
* @param systemStatus for logging
|
|
284
|
-
*/
|
|
285
|
-
protected _scaleDown(systemStatus: SystemInfo): void;
|
|
286
|
-
/**
|
|
287
|
-
* If there are no running tasks and this.isFinishedFunction() returns true then closes
|
|
288
|
-
* the pool and resolves the pool's promise returned by the run() method.
|
|
289
|
-
*
|
|
290
|
-
* It doesn't allow multiple concurrent runs of this method.
|
|
291
|
-
*/
|
|
292
|
-
protected _maybeFinish(): Promise<void>;
|
|
293
|
-
/**
|
|
294
|
-
* Cleans up resources.
|
|
295
|
-
*/
|
|
296
|
-
protected _destroy(): Promise<void>;
|
|
297
|
-
protected _incrementTasksDonePerSecond(intervalCallback: () => void): void;
|
|
298
|
-
protected get _isOverMaxRequestLimit(): boolean;
|
|
299
|
-
}
|
|
300
|
-
//# sourceMappingURL=autoscaled_pool.d.ts.map
|