Skip to content

Commit

Permalink
Fail on status code option + requeue fix (#480)
Browse files Browse the repository at this point in the history
Add fail on status code option, --failOnInvalidStatus to treat non-200
responses as failures. Can be useful especially when combined with
--failOnFailedSeed or --failOnFailedLimit

requeue: ensure requeued urls are requeued with same depth/priority, not
0
  • Loading branch information
ikreymer committed Mar 5, 2024
1 parent dd78457 commit 4520e9e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
22 changes: 16 additions & 6 deletions src/crawler.ts
Expand Up @@ -1586,20 +1586,30 @@ self.__bx_behaviors.selectMainBehavior();
});
}

// Handle 4xx or 5xx response as a page load error
const status = resp.status();
data.status = status;
if (isChromeError) {

let failed = isChromeError;

if (this.params.failOnInvalidStatus && status >= 400) {
// Handle 4xx or 5xx response as a page load error
failed = true;
}

if (failed) {
if (failCrawlOnError) {
logger.fatal("Seed Page Load Error, failing crawl", {
status,
...logDetails,
});
} else {
logger.error("Page Crashed on Load", {
status,
...logDetails,
});
logger.error(
isChromeError ? "Page Crashed on Load" : "Page Invalid Status",
{
status,
...logDetails,
},
);
throw new Error("logged");
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/util/argParser.ts
Expand Up @@ -484,6 +484,14 @@ class ArgParser {
default: 0,
},

failOnInvalidStatus: {
describe:
"If set, will treat pages with non-200 response as failures. When combined with --failOnFailedLimit or --failOnFailedSeed" +
"may result in crawl failing due to non-200 responses",
type: "boolean",
default: false,
},

customBehaviors: {
describe:
"injects a custom behavior file or set of behavior files in a directory",
Expand Down
5 changes: 4 additions & 1 deletion src/util/state.ts
Expand Up @@ -120,6 +120,7 @@ declare module "ioredis" {
pkeyUrl: string,
url: string,
maxRetryPending: number,
maxRegularDepth: number,
): Result<number, Context>;
}
}
Expand Down Expand Up @@ -253,7 +254,8 @@ if not res then
redis.call('hdel', KEYS[1], ARGV[1]);
if tonumber(data['retry']) <= tonumber(ARGV[2]) then
json = cjson.encode(data);
redis.call('zadd', KEYS[2], 0, json);
local score = (data['depth'] or 0) + ((data['extraHops'] or 0) * ARGV[3]);
redis.call('zadd', KEYS[2], score, json);
return 1;
else
return 2;
Expand Down Expand Up @@ -661,6 +663,7 @@ return 0;
this.pkey + ":" + url,
url,
this.maxRetryPending,
MAX_DEPTH,
);
switch (res) {
case 1:
Expand Down

0 comments on commit 4520e9e

Please sign in to comment.