Skip to content

Commit

Permalink
Added maxConcurrency config to set maximum concurrent parallel requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpdata committed Dec 4, 2023
1 parent e700f6e commit ac0ac25
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ type Config = {
maxFileSize?: number;
/** Optional maximum number tokens to include in the output file */
maxTokens?: number;
/** Optional - Maximum concurent parellel requets at a time */
maxConcurrency?: number;
};
```

Expand Down
2 changes: 1 addition & 1 deletion config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ export const defaultConfig: Config = {
url: "https://www.builder.io/c/docs/developers",
match: "https://www.builder.io/c/docs/**",
maxPagesToCrawl: 50,
outputFileName: "output.json",
maxConcurrency: 1,
};
7 changes: 7 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ export const configSchema = z.object({
* @example 5000
*/
maxTokens: z.number().int().positive().optional(),
/**
* **Optional:**
* maxConcurrency
* description: ( 0 = Unlimited, Doesn't stop until cancelled, undefined = max parellel requests possible )
* @default 1
* */
maxConcurrency: z.number().int().nonnegative().optional(),
});

export type Config = z.infer<typeof configSchema>;
6 changes: 1 addition & 5 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ export async function crawl(config: Config) {
globs:
typeof config.match === "string" ? [config.match] : config.match,
});
},
// Comment this option to scrape the full website.
maxRequestsPerCrawl: config.maxPagesToCrawl,
// Uncomment this option to see the browser window.
// headless: false,
maxConcurrency: config.maxConcurrency || 1 , // Set the max concurrency
preNavigationHooks: [
// Abort requests for certain resource types
async ({ page, log }) => {
Expand Down

0 comments on commit ac0ac25

Please sign in to comment.