Resume paused scrapes from their cursor

This commit is contained in:
Fisto
2026-09-17 00:14:57 +02:00
parent 089bca0d4f
commit 0664b54241
10 changed files with 110 additions and 0 deletions
+16
View File
@@ -182,6 +182,22 @@ export class ScrapeEngine {
this.stopRequested.add(id);
}
/** Continue a paused scrape from its stored cursor instead of walking the top again. */
async resume(scrapeId: string, backend: ScrapeBackend): Promise<ScrapeMeta | null> {
const meta = this.active.get(scrapeId) ?? readScrapeMeta(join(this.options.rootDir, scrapeId));
if (!meta) return null;
if (meta.state === "running" || meta.state === "queued") return { ...meta };
this.stopRequested.delete(scrapeId);
meta.state = "queued";
this.active.set(scrapeId, meta);
writeScrapeMeta(join(this.options.rootDir, scrapeId), meta);
this.queue.push({ meta, dir: join(this.options.rootDir, scrapeId), backend });
void this.processQueue();
return { ...meta };
}
/** Cache previews for rows a finished or paused scrape never reached. Returns the count. */
async backfillPreviews(scrapeId: string): Promise<number> {
const meta = this.active.get(scrapeId) ?? readScrapeMeta(join(this.options.rootDir, scrapeId));