Skip to content

Commit

Permalink
feat: Add HYPIXEL_GEN_MAX_WORKERS option to limit the number of wor…
Browse files Browse the repository at this point in the history
…kers
  • Loading branch information
robere2 committed Dec 4, 2023
1 parent 1f3706b commit 6d6ae0c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/schemas/src/HypixelGenerator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {getFullStack, logger, mergeSchemas, sortObject} from "./util";
import {HypixelApiError} from "./HypixelApiError";
import {Agent} from "undici";
import {HypixelRequestCallbackError} from "./HypixelRequestCallbackError";
import * as os from "os";

const __dirname = dirname(fileURLToPath(import.meta.url))

Expand All @@ -35,7 +36,9 @@ export class HypixelGenerator {
/**
* Worker pool is used to offload the CPU-heavy tasks of compiling, validating, and updating the schema.
*/
private readonly pool = workerpool.pool(join(__dirname, 'generator-worker.ts'));
private readonly pool = workerpool.pool(join(__dirname, 'generator-worker.ts'), {
maxWorkers: parseInt(process.env.HYPIXEL_GEN_MAX_WORKERS ?? "") || os.cpus().length - 1
});
/**
* Total number of URLs that have been processed & their schemas updated.
* @see {@link percentCompleted}
Expand Down
1 change: 1 addition & 0 deletions packages/schemas/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ declare global {
[key: string]: string | undefined;
HYPIXEL_GEN_API_KEY?: string;
HYPIXEL_GEN_WRITE_ERRORS?: string;
HYPIXEL_GEN_MAX_WORKERS?: string;
}
}
}
Expand Down

0 comments on commit 6d6ae0c

Please sign in to comment.