fix: add config validation and retry logic for failed jobs
- Add loadConfig() helper with clear errors for missing/malformed JSON - Replace raw JSON.parse(readFileSync(...)) in both entry points - Track retry_count on jobs; re-queue as 'new' up to max_retries (default 2) - Add max_retries and DEFAULT_MAX_RETRIES constant Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -53,3 +53,4 @@ export const NOTIFY_RATE_LIMIT_MS = 1500;
|
||||
|
||||
// --- Queue ---
|
||||
export const DEFAULT_REVIEW_WINDOW_MINUTES = 30;
|
||||
export const DEFAULT_MAX_RETRIES = 2;
|
||||
|
||||
@@ -3,13 +3,34 @@
|
||||
* Handles jobs_queue.json read/write/update
|
||||
*/
|
||||
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'fs';
|
||||
import { dirname } from 'path';
|
||||
import { dirname, resolve } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
const __dir = dirname(fileURLToPath(import.meta.url));
|
||||
const QUEUE_PATH = `${__dir}/../data/jobs_queue.json`;
|
||||
const LOG_PATH = `${__dir}/../data/applications_log.json`;
|
||||
|
||||
/**
|
||||
* Load and validate a JSON config file. Throws with a clear message on failure.
|
||||
*/
|
||||
export function loadConfig(filePath) {
|
||||
const resolved = resolve(filePath);
|
||||
if (!existsSync(resolved)) {
|
||||
throw new Error(`Config file not found: ${resolved}\nCopy the matching .example.json and fill in your values.`);
|
||||
}
|
||||
let raw;
|
||||
try {
|
||||
raw = readFileSync(resolved, 'utf8');
|
||||
} catch (e) {
|
||||
throw new Error(`Cannot read config file ${resolved}: ${e.message}`);
|
||||
}
|
||||
try {
|
||||
return JSON.parse(raw);
|
||||
} catch (e) {
|
||||
throw new Error(`Invalid JSON in ${resolved}: ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
function ensureDir(path) {
|
||||
const dir = dirname(path);
|
||||
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
||||
|
||||
Reference in New Issue
Block a user