Skip to content

support pause interrupt: #825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "browsertrix-crawler",
"version": "1.6.0",
"version": "1.6.1",
"main": "browsertrix-crawler",
"type": "module",
"repository": "https://github.com/webrecorder/browsertrix-crawler",
Expand Down
13 changes: 7 additions & 6 deletions src/crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1497,6 +1497,10 @@ self.__bx_behaviors.selectMainBehavior();
}
}

if (await this.crawlState.isCrawlPaused()) {
interrupt = InterruptReason.CrawlPaused;
}

if (interrupt) {
this.uploadAndDeleteLocal = true;
this.gracefulFinishOnInterrupt(interrupt);
Expand Down Expand Up @@ -1859,12 +1863,9 @@ self.__bx_behaviors.selectMainBehavior();
if (isFinished || (await this.crawlState.isCrawlCanceled())) {
return;
}
// if stopped, won't get anymore data
if (await this.crawlState.isCrawlStopped()) {
// possibly restarted after committing, so assume done here!
if ((await this.crawlState.numDone()) > 0) {
return;
}
// possibly restarted after committing, so assume done here!
if ((await this.crawlState.numDone()) > 0) {
return;
}
// fail crawl otherwise
logger.fatal("No WARC Files, assuming crawl failed");
Expand Down
1 change: 1 addition & 0 deletions src/util/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,5 @@ export enum InterruptReason {
DiskUtilization = 4,
BrowserCrashed = 5,
SignalInterrupted = 6,
CrawlPaused = 7,
}
8 changes: 8 additions & 0 deletions src/util/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,14 @@ return inx;
return false;
}

async isCrawlPaused() {
if ((await this.redis.get(`${this.key}:paused`)) === "1") {
return true;
}

return false;
}

async isCrawlCanceled() {
return (await this.redis.get(`${this.key}:canceled`)) === "1";
}
Expand Down
Loading