Skip to content

Commit

Permalink
misc exit features: (#366)
Browse files Browse the repository at this point in the history
- if interrupted (via signal or due to limits) and not finished, return error code 11 to indicate interruption
- allow stopping single instances with hset '<crawlid>:stopone' uid (similar to status)
- deliberate stop via redis not considered interruption (exit 0)
  • Loading branch information
ikreymer authored Sep 6, 2023
1 parent 3c2f5f8 commit b95c535
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
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

0 comments on commit b95c535

Please sign in to comment.