From f9446f5bee5dd3bd871507257e9365e40b070544 Mon Sep 17 00:00:00 2001 From: Claw Date: Fri, 6 Mar 2026 00:41:27 +0000 Subject: [PATCH] =?UTF-8?q?fix:=20resume=20lookback=20from=20progress=20fi?= =?UTF-8?q?le=20=E2=80=94=20don't=20reset=20to=202d=20when=20queue=20is=20?= =?UTF-8?q?non-empty?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/search_progress.json | 7 +++++++ data/searcher_last_run.json | 9 +++++++++ job_searcher.mjs | 16 +++++++++++++--- 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 data/search_progress.json create mode 100644 data/searcher_last_run.json diff --git a/data/search_progress.json b/data/search_progress.json new file mode 100644 index 0000000..bff6bb0 --- /dev/null +++ b/data/search_progress.json @@ -0,0 +1,7 @@ +{ + "lookback_days": 90, + "started_at": 1741220400000, + "completed": ["linkedin:Founding GTM"], + "pending": ["linkedin:Enterprise AE", "wellfound:Founding GTM"], + "stats:linkedin:Founding GTM": { "found": 913, "added": 814, "completed_at": 1741224000000 } +} diff --git a/data/searcher_last_run.json b/data/searcher_last_run.json new file mode 100644 index 0000000..4f68b5a --- /dev/null +++ b/data/searcher_last_run.json @@ -0,0 +1,9 @@ +{ + "started_at": 1772757505890, + "finished_at": null, + "finished": false, + "added": 40, + "seen": 146, + "skipped_dupes": 106, + "platforms": [] +} \ No newline at end of file diff --git a/job_searcher.mjs b/job_searcher.mjs index 033b305..58a1b2f 100644 --- a/job_searcher.mjs +++ b/job_searcher.mjs @@ -10,7 +10,7 @@ import { fileURLToPath } from 'url'; const __dir = dirname(fileURLToPath(import.meta.url)); import { addJobs, loadQueue, loadConfig } from './lib/queue.mjs'; -import { writeFileSync } from 'fs'; +import { writeFileSync, readFileSync, existsSync } from 'fs'; import { acquireLock } from './lib/lock.mjs'; import { createBrowser } from './lib/browser.mjs'; import { verifyLogin as liLogin, searchLinkedIn } from './lib/linkedin.mjs'; @@ -69,9 +69,19 @@ async function main() { console.log(''); } + // Determine lookback: check for an in-progress run first, then fall back to first-run/normal logic + const savedProgress = existsSync(resolve(__dir, 'data/search_progress.json')) + ? JSON.parse(readFileSync(resolve(__dir, 'data/search_progress.json'), 'utf8')) + : null; const isFirstRun = loadQueue().length === 0; - const lookbackDays = isFirstRun ? (searchConfig.first_run_days || DEFAULT_FIRST_RUN_DAYS) : (searchConfig.posted_within_days || 2); - if (isFirstRun) console.log(`📅 First run — looking back ${lookbackDays} days\n`); + const lookbackDays = savedProgress?.lookback_days + || (isFirstRun ? (searchConfig.first_run_days || DEFAULT_FIRST_RUN_DAYS) : (searchConfig.posted_within_days || 2)); + + if (savedProgress?.lookback_days) { + console.log(`🔁 Resuming ${lookbackDays}-day search run\n`); + } else if (isFirstRun) { + console.log(`📅 First run — looking back ${lookbackDays} days\n`); + } // Init progress tracking — enables resume on restart initProgress(resolve(__dir, 'data'), lookbackDays);