@crawlee/core 3.0.0-alpha.2 → 3.0.0-alpha.3
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/dist/LICENSE.md +201 -0
- package/{README.md → dist/README.md} +0 -0
- package/dist/autoscaling/autoscaled_pool.d.ts +286 -0
- package/dist/autoscaling/autoscaled_pool.d.ts.map +1 -0
- package/dist/autoscaling/autoscaled_pool.js +624 -0
- package/dist/autoscaling/autoscaled_pool.js.map +1 -0
- package/dist/autoscaling/index.d.ts +4 -0
- package/dist/autoscaling/index.d.ts.map +1 -0
- package/dist/autoscaling/index.js +7 -0
- package/dist/autoscaling/index.js.map +1 -0
- package/dist/autoscaling/snapshotter.d.ts +193 -0
- package/dist/autoscaling/snapshotter.d.ts.map +1 -0
- package/dist/autoscaling/snapshotter.js +377 -0
- package/dist/autoscaling/snapshotter.js.map +1 -0
- package/dist/autoscaling/system_status.d.ts +181 -0
- package/dist/autoscaling/system_status.d.ts.map +1 -0
- package/dist/autoscaling/system_status.js +194 -0
- package/dist/autoscaling/system_status.js.map +1 -0
- package/dist/cache_container.d.ts +18 -0
- package/dist/cache_container.d.ts.map +1 -0
- package/dist/cache_container.js +42 -0
- package/dist/cache_container.js.map +1 -0
- package/dist/configuration.d.ts +150 -0
- package/dist/configuration.d.ts.map +1 -0
- package/dist/configuration.js +284 -0
- package/dist/configuration.js.map +1 -0
- package/dist/constants.d.ts +3 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +6 -0
- package/dist/constants.js.map +1 -0
- package/dist/crawlers/crawler_commons.d.ts +23 -0
- package/dist/crawlers/crawler_commons.d.ts.map +1 -0
- package/dist/crawlers/crawler_commons.js +3 -0
- package/dist/crawlers/crawler_commons.js.map +1 -0
- package/dist/crawlers/crawler_extension.d.ts +11 -0
- package/dist/crawlers/crawler_extension.d.ts.map +1 -0
- package/dist/crawlers/crawler_extension.js +30 -0
- package/dist/crawlers/crawler_extension.js.map +1 -0
- package/dist/crawlers/crawler_utils.d.ts +25 -0
- package/dist/crawlers/crawler_utils.d.ts.map +1 -0
- package/dist/crawlers/crawler_utils.js +72 -0
- package/dist/crawlers/crawler_utils.js.map +1 -0
- package/dist/crawlers/index.d.ts +5 -0
- package/dist/crawlers/index.d.ts.map +1 -0
- package/dist/crawlers/index.js +8 -0
- package/dist/crawlers/index.js.map +1 -0
- package/dist/crawlers/statistics.d.ts +147 -0
- package/dist/crawlers/statistics.d.ts.map +1 -0
- package/dist/crawlers/statistics.js +360 -0
- package/dist/crawlers/statistics.js.map +1 -0
- package/dist/enqueue_links/enqueue_links.d.ts +138 -0
- package/dist/enqueue_links/enqueue_links.d.ts.map +1 -0
- package/dist/enqueue_links/enqueue_links.js +123 -0
- package/dist/enqueue_links/enqueue_links.js.map +1 -0
- package/dist/enqueue_links/index.d.ts +3 -0
- package/dist/enqueue_links/index.d.ts.map +1 -0
- package/dist/enqueue_links/index.js +6 -0
- package/dist/enqueue_links/index.js.map +1 -0
- package/dist/enqueue_links/shared.d.ts +60 -0
- package/dist/enqueue_links/shared.d.ts.map +1 -0
- package/dist/enqueue_links/shared.js +148 -0
- package/dist/enqueue_links/shared.js.map +1 -0
- package/dist/errors.d.ts +8 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +12 -0
- package/dist/errors.js.map +1 -0
- package/dist/events/event_manager.d.ts +41 -0
- package/dist/events/event_manager.d.ts.map +1 -0
- package/dist/events/event_manager.js +103 -0
- package/dist/events/event_manager.js.map +1 -0
- package/dist/events/index.d.ts +3 -0
- package/dist/events/index.d.ts.map +1 -0
- package/dist/events/index.js +6 -0
- package/dist/events/index.js.map +1 -0
- package/dist/events/local_event_manager.d.ts +32 -0
- package/dist/events/local_event_manager.d.ts.map +1 -0
- package/dist/events/local_event_manager.js +114 -0
- package/dist/events/local_event_manager.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +63 -0
- package/dist/log.d.ts +3 -0
- package/dist/log.d.ts.map +1 -0
- package/dist/log.js +12 -0
- package/dist/log.js.map +1 -0
- package/dist/package.json +82 -0
- package/dist/proxy_configuration.d.ts +181 -0
- package/dist/proxy_configuration.d.ts.map +1 -0
- package/dist/proxy_configuration.js +209 -0
- package/dist/proxy_configuration.js.map +1 -0
- package/dist/request.d.ts +174 -0
- package/dist/request.d.ts.map +1 -0
- package/dist/request.js +270 -0
- package/dist/request.js.map +1 -0
- package/dist/serialization.d.ts +33 -0
- package/dist/serialization.d.ts.map +1 -0
- package/dist/serialization.js +146 -0
- package/dist/serialization.js.map +1 -0
- package/dist/session_pool/errors.d.ts +8 -0
- package/dist/session_pool/errors.d.ts.map +1 -0
- package/dist/session_pool/errors.js +20 -0
- package/dist/session_pool/errors.js.map +1 -0
- package/dist/session_pool/events.d.ts +3 -0
- package/dist/session_pool/events.d.ts.map +1 -0
- package/dist/session_pool/events.js +6 -0
- package/dist/session_pool/events.js.map +1 -0
- package/dist/session_pool/index.d.ts +6 -0
- package/dist/session_pool/index.d.ts.map +1 -0
- package/dist/session_pool/index.js +9 -0
- package/dist/session_pool/index.js.map +1 -0
- package/dist/session_pool/session.d.ts +212 -0
- package/dist/session_pool/session.d.ts.map +1 -0
- package/dist/session_pool/session.js +360 -0
- package/dist/session_pool/session.js.map +1 -0
- package/dist/session_pool/session_pool.d.ts +222 -0
- package/dist/session_pool/session_pool.d.ts.map +1 -0
- package/dist/session_pool/session_pool.js +389 -0
- package/dist/session_pool/session_pool.js.map +1 -0
- package/dist/session_pool/session_utils.d.ts +9 -0
- package/dist/session_pool/session_utils.d.ts.map +1 -0
- package/dist/session_pool/session_utils.js +19 -0
- package/dist/session_pool/session_utils.js.map +1 -0
- package/dist/storages/dataset.d.ts +358 -0
- package/dist/storages/dataset.d.ts.map +1 -0
- package/dist/storages/dataset.js +415 -0
- package/dist/storages/dataset.js.map +1 -0
- package/dist/storages/index.d.ts +7 -0
- package/dist/storages/index.d.ts.map +1 -0
- package/dist/storages/index.js +11 -0
- package/dist/storages/index.js.map +1 -0
- package/dist/storages/key_value_store.d.ts +242 -0
- package/dist/storages/key_value_store.d.ts.map +1 -0
- package/dist/storages/key_value_store.js +319 -0
- package/dist/storages/key_value_store.js.map +1 -0
- package/dist/storages/request_list.d.ts +461 -0
- package/dist/storages/request_list.d.ts.map +1 -0
- package/dist/storages/request_list.js +715 -0
- package/dist/storages/request_list.js.map +1 -0
- package/dist/storages/request_queue.d.ts +312 -0
- package/dist/storages/request_queue.d.ts.map +1 -0
- package/dist/storages/request_queue.js +708 -0
- package/dist/storages/request_queue.js.map +1 -0
- package/dist/storages/storage.d.ts +260 -0
- package/dist/storages/storage.d.ts.map +1 -0
- package/dist/storages/storage.js +3 -0
- package/dist/storages/storage.js.map +1 -0
- package/dist/storages/storage_manager.d.ts +40 -0
- package/dist/storages/storage_manager.d.ts.map +1 -0
- package/dist/storages/storage_manager.js +119 -0
- package/dist/storages/storage_manager.js.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/typedefs.d.ts +12 -0
- package/dist/typedefs.d.ts.map +1 -0
- package/dist/typedefs.js +15 -0
- package/dist/typedefs.js.map +1 -0
- package/dist/validators.d.ts +21 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +26 -0
- package/dist/validators.js.map +1 -0
- package/package.json +11 -10
package/dist/LICENSE.md
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright 2018 Apify Technologies s.r.o.
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
File without changes
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { Log } from '@apify/log';
|
|
2
|
+
import { Configuration } from '../configuration';
|
|
3
|
+
import { SnapshotterOptions } from './snapshotter';
|
|
4
|
+
import { SystemInfo, SystemStatusOptions } from './system_status';
|
|
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 1000
|
|
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.95
|
|
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
|
+
log?: Log;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Manages a pool of asynchronous resource-intensive tasks that are executed in parallel.
|
|
101
|
+
* The pool only starts new tasks if there is enough free CPU and memory available
|
|
102
|
+
* and the Javascript event loop is not blocked.
|
|
103
|
+
*
|
|
104
|
+
* The information about the CPU and memory usage is obtained by the {@link Snapshotter} class,
|
|
105
|
+
* which makes regular snapshots of system resources that may be either local
|
|
106
|
+
* or from the Apify cloud infrastructure in case the process is running on the Apify platform.
|
|
107
|
+
* Meaningful data gathered from these snapshots is provided to `AutoscaledPool` by the {@link SystemStatus} class.
|
|
108
|
+
*
|
|
109
|
+
* Before running the pool, you need to implement the following three functions:
|
|
110
|
+
* {@link AutoscaledPoolOptions.runTaskFunction},
|
|
111
|
+
* {@link AutoscaledPoolOptions.isTaskReadyFunction} and
|
|
112
|
+
* {@link AutoscaledPoolOptions.isFinishedFunction}.
|
|
113
|
+
*
|
|
114
|
+
* The auto-scaled pool is started by calling the {@link AutoscaledPool.run} function.
|
|
115
|
+
* The pool periodically queries the {@link AutoscaledPoolOptions.isTaskReadyFunction} function
|
|
116
|
+
* for more tasks, managing optimal concurrency, until the function resolves to `false`. The pool then queries
|
|
117
|
+
* the {@link AutoscaledPoolOptions.isFinishedFunction}. If it resolves to `true`, the run finishes after all running tasks complete.
|
|
118
|
+
* If it resolves to `false`, it assumes there will be more tasks available later and keeps periodically querying for tasks.
|
|
119
|
+
* If any of the tasks throws then the {@link AutoscaledPool.run} function rejects the promise with an error.
|
|
120
|
+
*
|
|
121
|
+
* The pool evaluates whether it should start a new task every time one of the tasks finishes
|
|
122
|
+
* and also in the interval set by the `options.maybeRunIntervalSecs` parameter.
|
|
123
|
+
*
|
|
124
|
+
* **Example usage:**
|
|
125
|
+
*
|
|
126
|
+
* ```javascript
|
|
127
|
+
* const pool = new AutoscaledPool({
|
|
128
|
+
* maxConcurrency: 50,
|
|
129
|
+
* runTaskFunction: async () => {
|
|
130
|
+
* // Run some resource-intensive asynchronous operation here.
|
|
131
|
+
* },
|
|
132
|
+
* isTaskReadyFunction: async () => {
|
|
133
|
+
* // Tell the pool whether more tasks are ready to be processed.
|
|
134
|
+
* // Return true or false
|
|
135
|
+
* },
|
|
136
|
+
* isFinishedFunction: async () => {
|
|
137
|
+
* // Tell the pool whether it should finish
|
|
138
|
+
* // or wait for more tasks to become available.
|
|
139
|
+
* // Return true or false
|
|
140
|
+
* }
|
|
141
|
+
* });
|
|
142
|
+
*
|
|
143
|
+
* await pool.run();
|
|
144
|
+
* ```
|
|
145
|
+
* @category Scaling
|
|
146
|
+
*/
|
|
147
|
+
export declare class AutoscaledPool {
|
|
148
|
+
private readonly config;
|
|
149
|
+
private readonly log;
|
|
150
|
+
private readonly desiredConcurrencyRatio;
|
|
151
|
+
private readonly scaleUpStepRatio;
|
|
152
|
+
private readonly scaleDownStepRatio;
|
|
153
|
+
private readonly maybeRunIntervalMillis;
|
|
154
|
+
private readonly loggingIntervalMillis;
|
|
155
|
+
private readonly autoscaleIntervalMillis;
|
|
156
|
+
private readonly taskTimeoutMillis;
|
|
157
|
+
private readonly runTaskFunction;
|
|
158
|
+
private readonly isFinishedFunction;
|
|
159
|
+
private readonly isTaskReadyFunction;
|
|
160
|
+
private _minConcurrency;
|
|
161
|
+
private _maxConcurrency;
|
|
162
|
+
private _desiredConcurrency;
|
|
163
|
+
private _currentConcurrency;
|
|
164
|
+
private isStopped;
|
|
165
|
+
private lastLoggingTime;
|
|
166
|
+
private resolve;
|
|
167
|
+
private reject;
|
|
168
|
+
private snapshotter;
|
|
169
|
+
private systemStatus;
|
|
170
|
+
private poolPromise;
|
|
171
|
+
private autoscaleInterval;
|
|
172
|
+
private maybeRunInterval;
|
|
173
|
+
private queryingIsTaskReady;
|
|
174
|
+
private queryingIsFinished;
|
|
175
|
+
constructor(options: AutoscaledPoolOptions, config?: Configuration);
|
|
176
|
+
/**
|
|
177
|
+
* Gets the minimum number of tasks running in parallel.
|
|
178
|
+
*/
|
|
179
|
+
get minConcurrency(): number;
|
|
180
|
+
/**
|
|
181
|
+
* Sets the minimum number of tasks running in parallel.
|
|
182
|
+
*
|
|
183
|
+
* *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.
|
|
184
|
+
* If you're not sure, just keep the default value and the concurrency will scale up automatically.
|
|
185
|
+
*/
|
|
186
|
+
set minConcurrency(value: number);
|
|
187
|
+
/**
|
|
188
|
+
* Gets the maximum number of tasks running in parallel.
|
|
189
|
+
*/
|
|
190
|
+
get maxConcurrency(): number;
|
|
191
|
+
/**
|
|
192
|
+
* Sets the maximum number of tasks running in parallel.
|
|
193
|
+
*/
|
|
194
|
+
set maxConcurrency(value: number);
|
|
195
|
+
/**
|
|
196
|
+
* Gets the desired concurrency for the pool,
|
|
197
|
+
* which is an estimated number of parallel tasks that the system can currently support.
|
|
198
|
+
*/
|
|
199
|
+
get desiredConcurrency(): number;
|
|
200
|
+
/**
|
|
201
|
+
* Sets the desired concurrency for the pool, i.e. the number of tasks that should be running
|
|
202
|
+
* in parallel if there's large enough supply of tasks.
|
|
203
|
+
*/
|
|
204
|
+
set desiredConcurrency(value: number);
|
|
205
|
+
/**
|
|
206
|
+
* Gets the the number of parallel tasks currently running in the pool.
|
|
207
|
+
*/
|
|
208
|
+
get currentConcurrency(): number;
|
|
209
|
+
/**
|
|
210
|
+
* Runs the auto-scaled pool. Returns a promise that gets resolved or rejected once
|
|
211
|
+
* all the tasks are finished or one of them fails.
|
|
212
|
+
*/
|
|
213
|
+
run(): Promise<void>;
|
|
214
|
+
/**
|
|
215
|
+
* Aborts the run of the auto-scaled pool and destroys it. The promise returned from
|
|
216
|
+
* the {@link AutoscaledPool.run} function will immediately resolve, no more new tasks
|
|
217
|
+
* will be spawned and all running tasks will be left in their current state.
|
|
218
|
+
*
|
|
219
|
+
* Due to the nature of the tasks, auto-scaled pool cannot reliably guarantee abortion
|
|
220
|
+
* of all the running tasks, therefore, no abortion is attempted and some of the tasks
|
|
221
|
+
* may finish, while others may not. Essentially, auto-scaled pool doesn't care about
|
|
222
|
+
* their state after the invocation of `.abort()`, but that does not mean that some
|
|
223
|
+
* parts of their asynchronous chains of commands will not execute.
|
|
224
|
+
*/
|
|
225
|
+
abort(): Promise<void>;
|
|
226
|
+
/**
|
|
227
|
+
* Prevents the auto-scaled pool from starting new tasks, but allows the running ones to finish
|
|
228
|
+
* (unlike abort, which terminates them). Used together with {@link AutoscaledPool.resume}
|
|
229
|
+
*
|
|
230
|
+
* The function's promise will resolve once all running tasks have completed and the pool
|
|
231
|
+
* is effectively idle. If the `timeoutSecs` argument is provided, the promise will reject
|
|
232
|
+
* with a timeout error after the `timeoutSecs` seconds.
|
|
233
|
+
*
|
|
234
|
+
* The promise returned from the {@link AutoscaledPool.run} function will not resolve
|
|
235
|
+
* when `.pause()` is invoked (unlike abort, which resolves it).
|
|
236
|
+
*/
|
|
237
|
+
pause(timeoutSecs?: number): Promise<void>;
|
|
238
|
+
/**
|
|
239
|
+
* Resumes the operation of the autoscaled-pool by allowing more tasks to be run.
|
|
240
|
+
* Used together with {@link AutoscaledPool.pause}
|
|
241
|
+
*
|
|
242
|
+
* Tasks will automatically start running again in `options.maybeRunIntervalSecs`.
|
|
243
|
+
*/
|
|
244
|
+
resume(): void;
|
|
245
|
+
/**
|
|
246
|
+
* Starts a new task
|
|
247
|
+
* if the number of running tasks (current concurrency) is lower than desired concurrency
|
|
248
|
+
* and the system is not currently overloaded
|
|
249
|
+
* and this.isTaskReadyFunction() returns true.
|
|
250
|
+
*
|
|
251
|
+
* It doesn't allow multiple concurrent runs of this method.
|
|
252
|
+
*/
|
|
253
|
+
protected _maybeRunTask(intervalCallback?: () => void): Promise<void>;
|
|
254
|
+
/**
|
|
255
|
+
* Gets called every autoScaleIntervalSecs and evaluates the current system status.
|
|
256
|
+
* If the system IS NOT overloaded and the settings allow it, it scales up.
|
|
257
|
+
* If the system IS overloaded and the settings allow it, it scales down.
|
|
258
|
+
*/
|
|
259
|
+
protected _autoscale(intervalCallback: () => void): void;
|
|
260
|
+
/**
|
|
261
|
+
* Scales the pool up by increasing
|
|
262
|
+
* the desired concurrency by the scaleUpStepRatio.
|
|
263
|
+
*
|
|
264
|
+
* @param systemStatus for logging
|
|
265
|
+
*/
|
|
266
|
+
protected _scaleUp(systemStatus: SystemInfo): void;
|
|
267
|
+
/**
|
|
268
|
+
* Scales the pool down by decreasing
|
|
269
|
+
* the desired concurrency by the scaleDownStepRatio.
|
|
270
|
+
*
|
|
271
|
+
* @param systemStatus for logging
|
|
272
|
+
*/
|
|
273
|
+
protected _scaleDown(systemStatus: SystemInfo): void;
|
|
274
|
+
/**
|
|
275
|
+
* If there are no running tasks and this.isFinishedFunction() returns true then closes
|
|
276
|
+
* the pool and resolves the pool's promise returned by the run() method.
|
|
277
|
+
*
|
|
278
|
+
* It doesn't allow multiple concurrent runs of this method.
|
|
279
|
+
*/
|
|
280
|
+
protected _maybeFinish(): Promise<void>;
|
|
281
|
+
/**
|
|
282
|
+
* Cleans up resources.
|
|
283
|
+
*/
|
|
284
|
+
protected _destroy(): Promise<void>;
|
|
285
|
+
}
|
|
286
|
+
//# sourceMappingURL=autoscaled_pool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autoscaled_pool.d.ts","sourceRoot":"","sources":["../../src/autoscaling/autoscaled_pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY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