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

Fail on status code option + requeue fix #480

Merged
merged 1 commit into from Mar 5, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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