@crawlee/core 3.18.0 → 3.18.1-beta.1
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/configuration.js +13 -8
- package/package.json +5 -5
- package/storages/utils.js +11 -2
package/configuration.js
CHANGED
|
@@ -10,6 +10,7 @@ const fs_extra_1 = require("fs-extra");
|
|
|
10
10
|
const log_1 = tslib_1.__importStar(require("@apify/log"));
|
|
11
11
|
const events_1 = require("./events");
|
|
12
12
|
const typedefs_1 = require("./typedefs");
|
|
13
|
+
const memoryStorages = new Map();
|
|
13
14
|
/**
|
|
14
15
|
* `Configuration` is a value object holding Crawlee configuration. By default, there is a
|
|
15
16
|
* global singleton instance of this class available via `Configuration.getGlobalConfig()`.
|
|
@@ -200,17 +201,20 @@ class Configuration {
|
|
|
200
201
|
* @internal
|
|
201
202
|
*/
|
|
202
203
|
createMemoryStorage(options = {}) {
|
|
203
|
-
const
|
|
204
|
-
if (this.services.has(cacheKey)) {
|
|
205
|
-
return this.services.get(cacheKey);
|
|
206
|
-
}
|
|
207
|
-
const storage = new memory_storage_1.MemoryStorage({
|
|
204
|
+
const storageOptions = {
|
|
208
205
|
persistStorage: this.get('persistStorage'),
|
|
209
206
|
// Override persistStorage if user provides it via storageClientOptions
|
|
210
207
|
...options,
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
208
|
+
};
|
|
209
|
+
const cacheKey = `MemoryStorage-${JSON.stringify(storageOptions)}-${process.env.CRAWLEE_STORAGE_DIR ?? ''}`;
|
|
210
|
+
// Clients writing to the same directory are not independent, so they are shared between
|
|
211
|
+
// `Configuration` instances - otherwise they would purge each other's data mid-run.
|
|
212
|
+
// Purely in-memory clients have no such conflict and stay isolated per configuration.
|
|
213
|
+
const cache = storageOptions.persistStorage ? memoryStorages : this.services;
|
|
214
|
+
if (!cache.has(cacheKey)) {
|
|
215
|
+
cache.set(cacheKey, new memory_storage_1.MemoryStorage(storageOptions));
|
|
216
|
+
}
|
|
217
|
+
return cache.get(cacheKey);
|
|
214
218
|
}
|
|
215
219
|
useStorageClient(client) {
|
|
216
220
|
this.options.set('storageClient', client);
|
|
@@ -249,6 +253,7 @@ class Configuration {
|
|
|
249
253
|
*/
|
|
250
254
|
static resetGlobalState() {
|
|
251
255
|
delete this.globalConfig;
|
|
256
|
+
memoryStorages.clear();
|
|
252
257
|
}
|
|
253
258
|
buildOptions(options) {
|
|
254
259
|
// try to load configuration from crawlee.json as the baseline
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crawlee/core",
|
|
3
|
-
"version": "3.18.
|
|
3
|
+
"version": "3.18.1-beta.1",
|
|
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": ">=16.0.0"
|
|
@@ -59,9 +59,9 @@
|
|
|
59
59
|
"@apify/pseudo_url": "^2.0.30",
|
|
60
60
|
"@apify/timeout": "^0.4.0",
|
|
61
61
|
"@apify/utilities": "^2.7.10",
|
|
62
|
-
"@crawlee/memory-storage": "3.18.
|
|
63
|
-
"@crawlee/types": "3.18.
|
|
64
|
-
"@crawlee/utils": "3.18.
|
|
62
|
+
"@crawlee/memory-storage": "3.18.1-beta.1",
|
|
63
|
+
"@crawlee/types": "3.18.1-beta.1",
|
|
64
|
+
"@crawlee/utils": "3.18.1-beta.1",
|
|
65
65
|
"@sapphire/async-queue": "^1.5.1",
|
|
66
66
|
"@standard-schema/spec": "^1.0.0",
|
|
67
67
|
"@vladfrangu/async_event_emitter": "^2.2.2",
|
|
@@ -84,5 +84,5 @@
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
},
|
|
87
|
-
"gitHead": "
|
|
87
|
+
"gitHead": "9940ec8a3b663ff64e9674057e2ac0fa34ba63cf"
|
|
88
88
|
}
|
package/storages/utils.js
CHANGED
|
@@ -18,11 +18,20 @@ async function purgeDefaultStorages(configOrOptions, client) {
|
|
|
18
18
|
const { config = configuration_1.Configuration.getGlobalConfig(), onlyPurgeOnce = false } = options;
|
|
19
19
|
({ client = config.getStorageClient() } = options);
|
|
20
20
|
const casted = client;
|
|
21
|
+
const runPurge = async () => {
|
|
22
|
+
try {
|
|
23
|
+
await casted.purge?.();
|
|
24
|
+
}
|
|
25
|
+
catch (e) {
|
|
26
|
+
casted.__purged = undefined;
|
|
27
|
+
throw e;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
21
30
|
// if `onlyPurgeOnce` is true, will purge anytime this function is called, otherwise - only on start
|
|
22
31
|
if (!onlyPurgeOnce || (config.get('purgeOnStart') && !casted.__purged)) {
|
|
23
|
-
casted.__purged =
|
|
24
|
-
await casted.purge?.();
|
|
32
|
+
casted.__purged = runPurge();
|
|
25
33
|
}
|
|
34
|
+
await casted.__purged;
|
|
26
35
|
}
|
|
27
36
|
/**
|
|
28
37
|
* Easily create and manage state values. All state values are automatically persisted.
|