From 0a2ac11b01060c0465ff19b5c35267947de96220 Mon Sep 17 00:00:00 2001 From: Nick Sweeting Date: Mon, 5 Jan 2026 02:26:33 -0800 Subject: [PATCH] more binary fixes --- archivebox/machine/models.py | 17 +++---------- .../screenshot/on_Snapshot__51_screenshot.js | 24 +++++++------------ 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/archivebox/machine/models.py b/archivebox/machine/models.py index cb99cb57..07da29ec 100755 --- a/archivebox/machine/models.py +++ b/archivebox/machine/models.py @@ -384,15 +384,6 @@ class Binary(ModelWithHealthStats, ModelWithStateMachine): return None - @property - def output_dir(self): - """Return the output directory for this binary installation.""" - from pathlib import Path - from django.conf import settings - - DATA_DIR = getattr(settings, 'DATA_DIR', Path.cwd()) - return Path(DATA_DIR) / 'machines' / str(self.machine_id) / 'binaries' / self.name / str(self.id) - def update_and_requeue(self, **kwargs): """ Update binary fields and requeue for worker state machine. @@ -424,8 +415,6 @@ class Binary(ModelWithHealthStats, ModelWithStateMachine): # Create output directory output_dir = self.output_dir output_dir.mkdir(parents=True, exist_ok=True) - self.output_dir = str(output_dir) - self.save() # Discover ALL on_Binary__install_* hooks hooks = discover_hooks('Binary', config=config) @@ -452,7 +441,7 @@ class Binary(ModelWithHealthStats, ModelWithStateMachine): hook_kwargs['overrides'] = json.dumps(self.overrides) # Run the hook - result = run_hook( + process = run_hook( hook, output_dir=plugin_output_dir, config=config, @@ -461,11 +450,11 @@ class Binary(ModelWithHealthStats, ModelWithStateMachine): ) # Background hook (unlikely for binary installation, but handle it) - if result is None: + if process is None: continue # Failed or skipped hook - try next one - if result['returncode'] != 0: + if process.exit_code != 0: continue # Parse JSONL output to check for successful installation diff --git a/archivebox/plugins/screenshot/on_Snapshot__51_screenshot.js b/archivebox/plugins/screenshot/on_Snapshot__51_screenshot.js index 2ec2fdd4..fae0bf93 100644 --- a/archivebox/plugins/screenshot/on_Snapshot__51_screenshot.js +++ b/archivebox/plugins/screenshot/on_Snapshot__51_screenshot.js @@ -18,25 +18,17 @@ const path = require('path'); // Add NODE_MODULES_DIR to module resolution paths if set if (process.env.NODE_MODULES_DIR) module.paths.unshift(process.env.NODE_MODULES_DIR); -// Debug: Check NODE_V8_COVERAGE -console.error(`[DEBUG JS START] NODE_V8_COVERAGE=${process.env.NODE_V8_COVERAGE || 'NOT SET'}`); - -// Hook into process.exit to flush V8 coverage (for NODE_V8_COVERAGE support) -if (process.env.NODE_V8_COVERAGE) { - const originalExit = process.exit.bind(process); - process.exit = function(code) { - console.error(`[DEBUG] process.exit() override called with code=${code}`); +// Flush V8 coverage before exiting (for NODE_V8_COVERAGE support) +function flushCoverageAndExit(exitCode) { + if (process.env.NODE_V8_COVERAGE) { try { const v8 = require('v8'); - const result = v8.takeCoverage(); - console.error(`[DEBUG] v8.takeCoverage() returned: ${typeof result}`); + v8.takeCoverage(); } catch (e) { - // Log but don't block exit - we're exiting anyway - console.error(`[!] Coverage flush failed: ${e.message}`); + // Ignore errors during coverage flush } - originalExit(code); - }; - console.error('[DEBUG] process.exit() override installed'); + } + process.exit(exitCode); } const { @@ -51,7 +43,7 @@ const { if (!getEnvBool('SCREENSHOT_ENABLED', true)) { console.error('Skipping screenshot (SCREENSHOT_ENABLED=False)'); // Temporary failure (config disabled) - NO JSONL emission - process.exit(0); + flushCoverageAndExit(0); } // Now safe to require puppeteer