Skip to content

Commit

Permalink
fix(gatsby): correct bootstrap emit order (#12473)
Browse files Browse the repository at this point in the history
* fix(gatsby) correct bootstrap emit order
  • Loading branch information
freiksenet committed Mar 11, 2019
1 parent 331638a commit fceb4e7
Showing 1 changed file with 22 additions and 35 deletions.
57 changes: 22 additions & 35 deletions packages/gatsby/src/bootstrap/index.js
Expand Up @@ -488,49 +488,19 @@ module.exports = async (args: BootstrapArgs) => {

let onEndJob

const checkJobsDone = _.debounce(resolve => {
const checkJobsDone = _.debounce(async resolve => {
const state = store.getState()
if (state.jobs.active.length === 0) {
emitter.off(`END_JOB`, onEndJob)

report.log(``)
report.info(`bootstrap finished - ${process.uptime()} s`)
report.log(``)
emitter.emit(`BOOTSTRAP_FINISHED`)

// onPostBootstrap
activity = report.activityTimer(`onPostBootstrap`, {
parentSpan: bootstrapSpan,
})
activity.start()
apiRunnerNode(`onPostBootstrap`, { parentSpan: activity.span }).then(
() => {
activity.end()
bootstrapSpan.finish()
resolve({ graphqlRunner })
}
)
await finishBootstrap(bootstrapSpan)
resolve(graphqlRunner)
}
}, 100)

if (store.getState().jobs.active.length === 0) {
// onPostBootstrap
activity = report.activityTimer(`onPostBootstrap`, {
parentSpan: bootstrapSpan,
})
activity.start()
await apiRunnerNode(`onPostBootstrap`, { parentSpan: activity.span })
activity.end()

bootstrapSpan.finish()

report.log(``)
report.info(`bootstrap finished - ${process.uptime()} s`)
report.log(``)
emitter.emit(`BOOTSTRAP_FINISHED`)
return {
graphqlRunner,
}
await finishBootstrap(bootstrapSpan)
return { graphqlRunner }
} else {
return new Promise(resolve => {
// Wait until all side effect jobs are finished.
Expand All @@ -539,3 +509,20 @@ module.exports = async (args: BootstrapArgs) => {
})
}
}

const finishBootstrap = async bootstrapSpan => {
// onPostBootstrap
const activity = report.activityTimer(`onPostBootstrap`, {
parentSpan: bootstrapSpan,
})
activity.start()
await apiRunnerNode(`onPostBootstrap`, { parentSpan: activity.span })
activity.end()

report.log(``)
report.info(`bootstrap finished - ${process.uptime()} s`)
report.log(``)
emitter.emit(`BOOTSTRAP_FINISHED`)

bootstrapSpan.finish()
}

0 comments on commit fceb4e7

Please sign in to comment.