better concurrency debugging, --concurrency flag for npx quartz build

This commit is contained in:
Jacky Zhao 2023-08-08 22:52:49 -07:00
parent e4950e06a1
commit 49bd6bc3ff
9 changed files with 62 additions and 28 deletions
quartz/processors

View file

@ -56,6 +56,8 @@ async function transpileWorkerScript() {
platform: "node",
format: "esm",
packages: "external",
sourcemap: true,
sourcesContent: false,
plugins: [
{
name: "css-and-scripts-as-text",
@ -116,7 +118,7 @@ export async function parseMarkdown(ctx: BuildCtx, fps: FilePath[]): Promise<Pro
const log = new QuartzLogger(argv.verbose)
const CHUNK_SIZE = 128
let concurrency = fps.length < CHUNK_SIZE ? 1 : os.availableParallelism()
let concurrency = ctx.argv.concurrency ?? (fps.length < CHUNK_SIZE ? 1 : os.availableParallelism())
let res: ProcessedContent[] = []
log.start(`Parsing input files using ${concurrency} threads`)
@ -142,7 +144,11 @@ export async function parseMarkdown(ctx: BuildCtx, fps: FilePath[]): Promise<Pro
childPromises.push(pool.exec("parseFiles", [argv, chunk, ctx.allSlugs]))
}
const results: ProcessedContent[][] = await WorkerPromise.all(childPromises)
const results: ProcessedContent[][] = await WorkerPromise.all(childPromises).catch((err) => {
const errString = err.toString().slice("Error:".length)
console.error(errString)
process.exit(1)
})
res = results.flat()
await pool.terminate()
}