feedkeeper 0.44.1 → 0.44.2
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/package.json
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Worker } from "node:worker_threads";
|
|
2
2
|
const PARSE_TIMEOUT_MS = 15_000;
|
|
3
|
+
const WORKER_MAX_OLD_SPACE_MB = 256;
|
|
3
4
|
function readWorkerCount() {
|
|
4
5
|
const raw = process.env.EXTRACTOR_WORKERS;
|
|
5
6
|
if (raw === undefined)
|
|
@@ -9,10 +10,22 @@ function readWorkerCount() {
|
|
|
9
10
|
return 2;
|
|
10
11
|
return parsed;
|
|
11
12
|
}
|
|
13
|
+
function readMaxTasksPerWorker() {
|
|
14
|
+
const raw = process.env.EXTRACTOR_WORKER_MAX_TASKS;
|
|
15
|
+
if (raw === undefined)
|
|
16
|
+
return 250;
|
|
17
|
+
const parsed = Number(raw);
|
|
18
|
+
if (!Number.isSafeInteger(parsed) || parsed < 1 || parsed > 10_000)
|
|
19
|
+
return 250;
|
|
20
|
+
return parsed;
|
|
21
|
+
}
|
|
12
22
|
function createWorker() {
|
|
13
23
|
const isTs = import.meta.url.endsWith(".ts");
|
|
14
24
|
const url = new URL(isTs ? "./extractorWorker.ts" : "./extractorWorker.js", import.meta.url);
|
|
15
|
-
const
|
|
25
|
+
const resourceLimits = { maxOldGenerationSizeMb: WORKER_MAX_OLD_SPACE_MB };
|
|
26
|
+
const worker = isTs
|
|
27
|
+
? new Worker(url, { execArgv: ["--import", "tsx"], resourceLimits })
|
|
28
|
+
: new Worker(url, { resourceLimits });
|
|
16
29
|
worker.unref();
|
|
17
30
|
return worker;
|
|
18
31
|
}
|
|
@@ -32,12 +45,17 @@ class ExtractorWorkerPool {
|
|
|
32
45
|
}
|
|
33
46
|
spawnSlot() {
|
|
34
47
|
const worker = createWorker();
|
|
35
|
-
const slot = { worker, busy: false, current: null, timer: null };
|
|
48
|
+
const slot = { worker, busy: false, current: null, timer: null, tasksProcessed: 0 };
|
|
36
49
|
worker.on("message", (msg) => {
|
|
37
50
|
const task = slot.current;
|
|
38
51
|
if (!task || task.id !== msg.id)
|
|
39
52
|
return;
|
|
40
53
|
this.finishSlot(slot);
|
|
54
|
+
slot.tasksProcessed++;
|
|
55
|
+
// Recycle workers periodically so long-lived JSDOM heaps return memory to the OS.
|
|
56
|
+
if (slot.tasksProcessed >= readMaxTasksPerWorker()) {
|
|
57
|
+
this.dropSlot(slot);
|
|
58
|
+
}
|
|
41
59
|
if (msg.error)
|
|
42
60
|
task.reject(new Error(msg.error));
|
|
43
61
|
else if (msg.result)
|
|
@@ -12,9 +12,9 @@ import { sourceHost } from "./requestGate.js";
|
|
|
12
12
|
// Kept for integrations importing the old constant; retries now belong to individual articles.
|
|
13
13
|
export const FULL_TEXT_BLOCK_THRESHOLD = 2;
|
|
14
14
|
function recordAttempt(id, status) {
|
|
15
|
-
const
|
|
15
|
+
const longPause = ["paywall", "consent_wall", "failed", "bot_blocked", "timeout"].includes(status);
|
|
16
16
|
const retry = status === "ready" || status === "feed_only" ? null :
|
|
17
|
-
new Date(Date.now() + (
|
|
17
|
+
new Date(Date.now() + (longPause ? 7 * 86400_000 : status === "partial" ? 86400_000 : 3600_000)).toISOString();
|
|
18
18
|
db.prepare("UPDATE items SET extraction_status = ?, extraction_attempted_at = ?, extraction_retry_at = ? WHERE id = ?")
|
|
19
19
|
.run(status, new Date().toISOString(), retry, id);
|
|
20
20
|
}
|
|
@@ -73,7 +73,7 @@ export async function executeFullText(userId, itemId, force, priority) {
|
|
|
73
73
|
if (result.status !== "ok") {
|
|
74
74
|
recordAttempt(itemId, result.status);
|
|
75
75
|
return { ok: false, error: result.status === "failed" ? "could_not_extract_content" : result.status,
|
|
76
|
-
...(result.status === "
|
|
76
|
+
...(result.status === "timeout" ? { retryable: true } : {}) };
|
|
77
77
|
}
|
|
78
78
|
const current = findItemById(itemId);
|
|
79
79
|
if (!current || current.link !== item.link)
|
|
@@ -27,6 +27,7 @@ export function scheduleFullTexts() {
|
|
|
27
27
|
AND e.status = 'active' AND e.expires_at > strftime('%Y-%m-%dT%H:%M:%fZ','now')
|
|
28
28
|
AND i.link IS NOT NULL AND i.full_content_html IS NULL
|
|
29
29
|
AND i.extraction_status != 'feed_only'
|
|
30
|
+
AND i.extraction_status = 'pending'
|
|
30
31
|
AND (i.extraction_retry_at IS NULL OR i.extraction_retry_at <= strftime('%Y-%m-%dT%H:%M:%fZ','now'))
|
|
31
32
|
AND NOT EXISTS (SELECT 1 FROM full_text_jobs j WHERE j.item_id = i.id)
|
|
32
33
|
|
|
@@ -39,6 +40,7 @@ export function scheduleFullTexts() {
|
|
|
39
40
|
AND NOT EXISTS (SELECT 1 FROM subscriptions disabled WHERE disabled.user_id=b.user_id AND disabled.feed_id=i.feed_id AND disabled.full_text_mode='never')
|
|
40
41
|
AND i.link IS NOT NULL AND i.full_content_html IS NULL
|
|
41
42
|
AND i.extraction_status != 'feed_only'
|
|
43
|
+
AND i.extraction_status = 'pending'
|
|
42
44
|
AND (i.extraction_retry_at IS NULL OR i.extraction_retry_at <= strftime('%Y-%m-%dT%H:%M:%fZ','now'))
|
|
43
45
|
AND NOT EXISTS (SELECT 1 FROM full_text_jobs j WHERE j.item_id = i.id)
|
|
44
46
|
|
|
@@ -51,6 +53,7 @@ export function scheduleFullTexts() {
|
|
|
51
53
|
AND NOT EXISTS (SELECT 1 FROM subscriptions disabled WHERE disabled.user_id=n.user_id AND disabled.feed_id=i.feed_id AND disabled.full_text_mode='never')
|
|
52
54
|
AND i.link IS NOT NULL AND i.full_content_html IS NULL
|
|
53
55
|
AND i.extraction_status != 'feed_only'
|
|
56
|
+
AND i.extraction_status = 'pending'
|
|
54
57
|
AND (i.extraction_retry_at IS NULL OR i.extraction_retry_at <= strftime('%Y-%m-%dT%H:%M:%fZ','now'))
|
|
55
58
|
AND NOT EXISTS (SELECT 1 FROM full_text_jobs j WHERE j.item_id = i.id)
|
|
56
59
|
|
|
@@ -63,6 +66,8 @@ export function scheduleFullTexts() {
|
|
|
63
66
|
AND COALESCE(s.full_text_mode, 'auto') = 'auto'
|
|
64
67
|
AND i.link IS NOT NULL AND i.full_content_html IS NULL
|
|
65
68
|
AND i.extraction_status != 'feed_only'
|
|
69
|
+
AND i.extraction_status = 'pending'
|
|
70
|
+
AND i.created_at >= strftime('%Y-%m-%dT%H:%M:%fZ','now','-14 days')
|
|
66
71
|
AND (i.extraction_retry_at IS NULL OR i.extraction_retry_at <= strftime('%Y-%m-%dT%H:%M:%fZ','now'))
|
|
67
72
|
AND NOT EXISTS (SELECT 1 FROM full_text_jobs j WHERE j.item_id = i.id)
|
|
68
73
|
)
|
|
@@ -300,7 +305,7 @@ async function execute(job, host) {
|
|
|
300
305
|
return;
|
|
301
306
|
}
|
|
302
307
|
if (!result.ok && result.retryable) {
|
|
303
|
-
const retryAt = Math.max(Date.now() +
|
|
308
|
+
const retryAt = Math.max(Date.now() + 7 * 86400_000, result.retryAt ?? 0);
|
|
304
309
|
db.prepare("UPDATE items SET extraction_status=?,extraction_retry_at=? WHERE id=?")
|
|
305
310
|
.run(result.error === "source_busy" ? "bot_blocked" : "failed", new Date(retryAt).toISOString(), job.item_id);
|
|
306
311
|
}
|