Skip to content
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

improve exit features: individual instance exit + exit code for interrupt #366

Merged
merged 1 commit into from
Sep 6, 2023
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
10 changes: 7 additions & 3 deletions crawler.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ export class Crawler {
} catch (e) {
//logger.fatal("Unable to connect to state store Redis: " + redisUrl);
logger.warn(`Waiting for redis at ${redisUrl}`, {}, "state");
await sleep(3);
await sleep(1);
}
}

Expand Down Expand Up @@ -304,12 +304,16 @@ export class Crawler {
async run() {
await this.bootstrap();

let status;
let status = "done";
let exitCode = 0;

try {
await this.crawl();
status = (!this.interrupted ? "done" : "interrupted");
const finished = await this.crawlState.isFinished();
if (this.interrupted && !finished) {
status = "interrupted";
exitCode = 11;
}
} catch(e) {
logger.error("Crawl failed", e);
exitCode = 9;
Expand Down
10 changes: 9 additions & 1 deletion util/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,15 @@ return 0;
}

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

if (await this.redis.hget(`${this.key}:stopone`, this.uid) === "1") {
return true;
}

return false;
}

// note: not currently called in crawler, but could be
Expand Down