From 3a52bdc72e7a2ecc44682218cb48a54fb1f7aaa4 Mon Sep 17 00:00:00 2001 From: Claw Date: Fri, 6 Mar 2026 16:25:09 +0000 Subject: [PATCH] =?UTF-8?q?feat:=20dynamic=20lookback=20window=20=E2=80=94?= =?UTF-8?q?=20time=20since=20last=20run=20=C3=97=201.25=20buffer=20(min=20?= =?UTF-8?q?4h)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- job_searcher.mjs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/job_searcher.mjs b/job_searcher.mjs index 3b0ff9a..1f31aaa 100644 --- a/job_searcher.mjs +++ b/job_searcher.mjs @@ -85,13 +85,31 @@ async function main() { ? JSON.parse(readFileSync(resolve(__dir, 'data/search_progress.json'), 'utf8')) : null; const isFirstRun = loadQueue().length === 0; + + // Dynamic lookback: time since last run × 1.25 buffer (min 4h, max first_run_days) + function dynamicLookbackDays() { + const lastRunPath = resolve(__dir, 'data/searcher_last_run.json'); + if (!existsSync(lastRunPath)) return searchConfig.posted_within_days || 2; + const lastRun = JSON.parse(readFileSync(lastRunPath, 'utf8')); + const lastRanAt = lastRun.started_at || lastRun.finished_at; + if (!lastRanAt) return searchConfig.posted_within_days || 2; + const hoursSince = (Date.now() - new Date(lastRanAt).getTime()) / (1000 * 60 * 60); + const buffered = hoursSince * 1.25; + const minHours = 4; + const maxDays = searchConfig.first_run_days || DEFAULT_FIRST_RUN_DAYS; + return Math.min(Math.max(buffered / 24, minHours / 24), maxDays); + } + const lookbackDays = savedProgress?.lookback_days - || (isFirstRun ? (searchConfig.first_run_days || DEFAULT_FIRST_RUN_DAYS) : (searchConfig.posted_within_days || 2)); + || (isFirstRun ? (searchConfig.first_run_days || DEFAULT_FIRST_RUN_DAYS) : dynamicLookbackDays()); if (savedProgress?.lookback_days) { - console.log(`🔁 Resuming ${lookbackDays}-day search run\n`); + console.log(`🔁 Resuming ${lookbackDays.toFixed(2)}-day search run\n`); } else if (isFirstRun) { console.log(`📅 First run — looking back ${lookbackDays} days\n`); + } else { + const hours = (lookbackDays * 24).toFixed(1); + console.log(`⏱️ Dynamic lookback: ${hours}h (time since last run × 1.25)\n`); } // Init progress tracking — enables resume on restart