Resume paused scrapes from their cursor
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user