fix(JobExecutor#exec): correctly log the error

This commit is contained in:
Julien Fontanet
2016-07-29 15:20:06 +02:00
parent 26c5c6152d
commit 6d1e410bfd
3 changed files with 15 additions and 8 deletions

View File

@@ -12,6 +12,7 @@ import { BaseError } from 'make-error'
import { crossProduct } from './math'
import {
forEach,
serializeError,
thunkToArray
} from './utils'
@@ -117,11 +118,11 @@ export default class JobExecutor {
event: 'job.end',
runJobId
})
} catch (e) {
} catch (error) {
this._logger.error(`The execution of ${job.id} has failed.`, {
event: 'job.end',
runJobId,
error: e
error: serializeError(error)
})
}
}

View File

@@ -484,6 +484,15 @@ export const scheduleFn = (cronTime, fn, timeZone) => {
// -------------------------------------------------------------------
// Create a serializable object from an error.
export const serializeError = error => ({
message: error.message,
stack: error.stack,
...error // Copy enumerable properties.
})
// -------------------------------------------------------------------
// Create an array which contains the results of one thunk function.
// Only works with synchronous thunks.
export const thunkToArray = thunk => {

View File

@@ -15,7 +15,8 @@ import {
createRawObject,
forEach,
isFunction,
noop
noop,
serializeError
} from '../utils'
// ===================================================================
@@ -258,11 +259,7 @@ export default class Api {
method: name,
params,
duration: Date.now() - startTime,
error: {
message: error.message,
stack: error.stack,
...error // Copy enumerable properties.
}
error: serializeError(error)
}
const message = `${userName} | ${name}(${JSON.stringify(params)}) [${ms(Date.now() - startTime)}] =!> ${error}`