fix: jobs/worker - pass through job error from worker process (#3822)
This commit is contained in:
parent
a20f70ed8d
commit
71aa0c9346
@ -55,14 +55,22 @@ class Job {
|
|||||||
`--job=${this.name}`,
|
`--job=${this.name}`,
|
||||||
`--data=${data}`
|
`--data=${data}`
|
||||||
], {
|
], {
|
||||||
cwd: WIKI.ROOTPATH
|
cwd: WIKI.ROOTPATH,
|
||||||
|
stdio: ['inherit', 'inherit', 'pipe', 'ipc']
|
||||||
})
|
})
|
||||||
|
const stderr = [];
|
||||||
|
proc.stderr.on('data', chunk => stderr.push(chunk))
|
||||||
this.finished = new Promise((resolve, reject) => {
|
this.finished = new Promise((resolve, reject) => {
|
||||||
proc.on('exit', (code, signal) => {
|
proc.on('exit', (code, signal) => {
|
||||||
|
const data = Buffer.concat(stderr).toString()
|
||||||
if (code === 0) {
|
if (code === 0) {
|
||||||
resolve()
|
resolve(data)
|
||||||
} else {
|
} else {
|
||||||
reject(signal)
|
const err = new Error(`Error when running job ${this.name}: ${data}`)
|
||||||
|
err.exitSignal = signal
|
||||||
|
err.exitCode = code
|
||||||
|
err.stderr = data
|
||||||
|
reject(err)
|
||||||
}
|
}
|
||||||
proc.kill()
|
proc.kill()
|
||||||
})
|
})
|
||||||
|
@ -14,6 +14,11 @@ WIKI.logger = require('./logger').init('JOB')
|
|||||||
const args = require('yargs').argv
|
const args = require('yargs').argv
|
||||||
|
|
||||||
;(async () => {
|
;(async () => {
|
||||||
|
try {
|
||||||
await require(`../jobs/${args.job}`)(args.data)
|
await require(`../jobs/${args.job}`)(args.data)
|
||||||
process.exit(0)
|
process.exit(0)
|
||||||
|
} catch (e) {
|
||||||
|
await new Promise(resolve => process.stderr.write(e.message, resolve))
|
||||||
|
process.exit(1)
|
||||||
|
}
|
||||||
})()
|
})()
|
||||||
|
@ -74,5 +74,7 @@ module.exports = async (pageId) => {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
WIKI.logger.error(`Rebuilding page tree: [ FAILED ]`)
|
WIKI.logger.error(`Rebuilding page tree: [ FAILED ]`)
|
||||||
WIKI.logger.error(err.message)
|
WIKI.logger.error(err.message)
|
||||||
|
// exit process with error code
|
||||||
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,5 +90,7 @@ module.exports = async (pageId) => {
|
|||||||
} catch (err) {
|
} catch (err) {
|
||||||
WIKI.logger.error(`Rendering page ID ${pageId}: [ FAILED ]`)
|
WIKI.logger.error(`Rendering page ID ${pageId}: [ FAILED ]`)
|
||||||
WIKI.logger.error(err.message)
|
WIKI.logger.error(err.message)
|
||||||
|
// exit process with error code
|
||||||
|
throw err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user