Skip to content

implement prerender queue failOnError #4637

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/start-plugin-core/src/nitro-plugin/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,10 @@ export async function prerender({
const retriesByPath = new Map<string, number>()
const concurrency = options.prerender?.concurrency ?? os.cpus().length
logger.info(`Concurrency: ${concurrency}`)
const queue = new Queue({ concurrency })
const queue = new Queue({
concurrency,
failOnError: options.prerender?.failOnError,
})

options.pages.forEach((page) => addCrawlPageTask(page))

Expand Down
9 changes: 8 additions & 1 deletion packages/start-plugin-core/src/nitro-plugin/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ interface PoolConfig {
concurrency?: number
started?: boolean
tasks?: Array<() => Promise<any>>
failOnError?: boolean
}

const defaultConfig: PoolConfig = {
Expand All @@ -19,15 +20,17 @@ export class Queue<T> {
private active: Array<() => Promise<any>> = []
private pending: Array<() => Promise<any>>
private currentConcurrency: number
private failOnError: boolean

constructor(config: PoolConfig = defaultConfig) {
const { concurrency, started, tasks } = {
const { concurrency, started, tasks, failOnError } = {
...defaultConfig,
...config,
}
this.running = started!
this.pending = tasks as Array<() => Promise<any>>
this.currentConcurrency = concurrency!
this.failOnError = Boolean(failOnError)
}

private tick() {
Expand All @@ -51,6 +54,10 @@ export class Queue<T> {
res = await nextFn()
success = true
} catch (e) {
if (this.failOnError) {
console.error(e)
process.exit(1)
}
error = e
}
this.active = this.active.filter((d) => d !== nextFn)
Expand Down