From 9f63a2579c15abc8bae329a90e8f8ffa4f24c30d Mon Sep 17 00:00:00 2001 From: Adam Wright Date: Mon, 2 Nov 2026 21:14:21 +0000 Subject: [PATCH] Render service, from #778's review: RENDER_FILES checked only when started The RENDER_FILES check ran whenever service.ts was imported, so a test run with a bad RENDER_FILES in the shell stopped its worker. It now runs only when the service is started. RENDER_CACHE_MAX's "0 disables" read as turning the cache off; 0 removes the size limit, and the README and header now say the cache cannot be turned off and a fresh RENDER_CACHE_KEY gives a cold run. Co-Authored-By: Claude Opus 5.5 --- tools/render/README.md | 23 ++++++++++++----------- tools/render/service.ts | 17 ++++++++++------- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/tools/render/README.md b/tools/render/README.md index 6ced1dd9..f45307a0 100644 --- a/tools/render/README.md +++ b/tools/render/README.md @@ -244,17 +244,18 @@ curl -o out.pptx 'http://127.0.0.1:4310/render/R-HSA-109606.pptx' curl -s http://127.0.0.1:4310/health ``` -| variable | default | | -| -------------------- | --------------------- | -------------------------------------------------------------------------- | -| `RENDER_PORT` | 4310 | | -| `RENDER_HOST` | 127.0.0.1 | set `0.0.0.0` only behind something that decides who may cause work | -| `RENDER_BASE` | http://localhost:4200 | site to render against | -| `RENDER_CACHE` | `.render-cache` | | -| `RENDER_CACHE_KEY` | the code's (`v12`) | override only to invalidate by hand; the code bumps it when output changes | -| `RENDER_CONCURRENCY` | 2 | simultaneous renders | -| `RENDER_QUEUE` | 8 | pending renders before 503 | -| `RENDER_TIMEOUT` | 45000 | ms before a render is abandoned | -| `RENDER_FILES` | unset | a folder laid out as the download site; see below | +| variable | default | | +| -------------------- | --------------------- | -------------------------------------------------------------------------------------------------------------------------- | +| `RENDER_PORT` | 4310 | | +| `RENDER_HOST` | 127.0.0.1 | set `0.0.0.0` only behind something that decides who may cause work | +| `RENDER_BASE` | http://localhost:4200 | site to render against | +| `RENDER_CACHE` | `.render-cache` | | +| `RENDER_CACHE_KEY` | the code's (`v12`) | override only to invalidate by hand; the code bumps it when output changes | +| `RENDER_CACHE_MAX` | 2 GB | bytes of figures kept; 0 keeps everything. The cache cannot be turned off: for a cold run, give a fresh `RENDER_CACHE_KEY` | +| `RENDER_CONCURRENCY` | 2 | simultaneous renders | +| `RENDER_QUEUE` | 8 | pending renders before 503 | +| `RENDER_TIMEOUT` | 45000 | ms before a render is abandoned | +| `RENDER_FILES` | unset | a folder laid out as the download site; see below | **The release's files.** The render page fetches a diagram's layout (`{release}/diagram/{id}.json`, `.graph.json`) and an illustration diff --git a/tools/render/service.ts b/tools/render/service.ts index 8b4d7b13..625e411c 100644 --- a/tools/render/service.ts +++ b/tools/render/service.ts @@ -32,7 +32,8 @@ * RENDER_CACHE_KEY salt; change it to invalidate everything (e.g. release) * RENDER_CONCURRENCY simultaneous renders, default 2 * RENDER_QUEUE pending renders before 503, default 8 - * RENDER_CACHE_MAX bytes of cache to keep, default 2 GB (0 disables) + * RENDER_CACHE_MAX bytes of cache to keep, default 2 GB (0: no limit; the + * cache cannot be turned off -- a fresh RENDER_CACHE_KEY is cold) * RENDER_TIMEOUT ms before a render is abandoned, default 45000 * RENDER_FILES a folder laid out as the download site, read instead of it * (local-files.ts); unset, the page fetches from the site @@ -111,12 +112,6 @@ const CACHE_KEY = process.env['RENDER_CACHE_KEY'] || 'v12'; // for the page to read instead of the site (local-files.ts). Unset, it fetches // them from the site, as a reader's browser does. const FILES = process.env['RENDER_FILES'] || undefined; -// A mistyped folder would otherwise fail every render after the full timeout, -// with /health saying the files are local. -if (FILES && !statSync(FILES, { throwIfNoEntry: false })?.isDirectory()) { - console.error(`RENDER_FILES is not a directory: ${FILES}`); - process.exit(2); -} const CONCURRENCY = Number(process.env['RENDER_CONCURRENCY'] || 2); // Generous next to a real render, which is 3-8s, but far short of the two // minutes a page that never becomes ready would otherwise hold a browser for. @@ -773,6 +768,14 @@ function startedDirectly() { } const started = startedDirectly(); +// A mistyped folder would otherwise fail every render after the full timeout, +// with /health saying the files are local. Checked only when the service is +// started, so a test importing this module is never stopped by the shell's +// RENDER_FILES. +if (started && FILES && !statSync(FILES, { throwIfNoEntry: false })?.isDirectory()) { + console.error(`RENDER_FILES is not a directory: ${FILES}`); + process.exit(2); +} const server = started ? app.listen(PORT, HOST, () => { console.log(`render service on http://${HOST}:${PORT}`);