Files
blog-eleventy-indiekit/lib/og-cli.js
Ricardo db10d9cfbf fix(og): batch spawning to prevent OOM during watcher rebuilds
Full OG regeneration (2,350 images) OOM-kills when the Eleventy watcher
is running (~1.8 GB RSS), leaving only ~1.2 GB headroom in the 3 GB
container. WASM native memory from Satori/Resvg grows beyond what GC
can reclaim within a single process.

Solution: spawn og-cli in batches of 100 images. Each invocation exits
after its batch, fully releasing all WASM native memory. Exit code 2
signals "more work remains" and the spawner re-loops. Peak memory per
batch stays under ~500 MB regardless of total image count.

Also seed newManifest from existing manifest so unscanned entries survive
batch writes.

Confab-Link: http://localhost:8080/sessions/edb1b7b0-da66-4486-bd9c-d1cfa7553b88
2026-03-09 17:37:17 +01:00

31 lines
1.0 KiB
JavaScript

#!/usr/bin/env node
/**
* CLI entry point for OG image generation.
* Runs as a separate process to isolate memory from Eleventy.
*
* Usage: node lib/og-cli.js <contentDir> <cacheDir> <siteName> [batchSize]
*
* batchSize: Max images to generate per invocation (0 = unlimited).
* When set, exits after generating that many images so the caller
* can re-spawn (releasing all WASM native memory between batches).
* Exit code 2 = batch complete, more work remains.
*/
import { generateOgImages } from "./og.js";
const [contentDir, cacheDir, siteName, batchSizeStr] = process.argv.slice(2);
if (!contentDir || !cacheDir || !siteName) {
console.error("[og] Usage: node og-cli.js <contentDir> <cacheDir> <siteName> [batchSize]");
process.exit(1);
}
const batchSize = parseInt(batchSizeStr, 10) || 0;
const result = await generateOgImages(contentDir, cacheDir, siteName, batchSize);
// Exit code 2 signals "batch complete, more images remain"
if (result?.hasMore) {
process.exit(2);
}