chore(JobExecutor#_execCall): forEach+Array#push → mapToArray

This commit is contained in:
Julien Fontanet 2016-08-17 18:13:30 +02:00
parent d08a04959c
commit 6c4e57aae0

View File

@ -11,7 +11,7 @@ import { BaseError } from 'make-error'
import { crossProduct } from './math' import { crossProduct } from './math'
import { import {
forEach, mapToArray,
serializeError, serializeError,
thunkToArray thunkToArray
} from './utils' } from './utils'
@ -136,7 +136,6 @@ export default class JobExecutor {
: [{}] // One call with no parameters : [{}] // One call with no parameters
const connection = this.xo.createUserConnection() const connection = this.xo.createUserConnection()
const promises = []
connection.set('user_id', job.userId) connection.set('user_id', job.userId)
@ -146,7 +145,7 @@ export default class JobExecutor {
calls: {} calls: {}
} }
forEach(paramsFlatVector, params => { const promises = mapToArray(paramsFlatVector, params => {
const runCallId = this._logger.notice(`Starting ${job.method} call. (${job.id})`, { const runCallId = this._logger.notice(`Starting ${job.method} call. (${job.id})`, {
event: 'jobCall.start', event: 'jobCall.start',
runJobId, runJobId,
@ -160,31 +159,29 @@ export default class JobExecutor {
start: Date.now() start: Date.now()
} }
promises.push( return this.xo.callApiMethod(connection, job.method, assign({}, params)).then(
this.xo.callApiMethod(connection, job.method, assign({}, params)).then( value => {
value => { this._logger.notice(`Call ${job.method} (${runCallId}) is a success. (${job.id})`, {
this._logger.notice(`Call ${job.method} (${runCallId}) is a success. (${job.id})`, { event: 'jobCall.end',
event: 'jobCall.end', runJobId,
runJobId, runCallId,
runCallId, returnedValue: value
returnedValue: value })
})
call.returnedValue = value call.returnedValue = value
call.end = Date.now() call.end = Date.now()
}, },
reason => { reason => {
this._logger.notice(`Call ${job.method} (${runCallId}) has failed. (${job.id})`, { this._logger.notice(`Call ${job.method} (${runCallId}) has failed. (${job.id})`, {
event: 'jobCall.end', event: 'jobCall.end',
runJobId, runJobId,
runCallId, runCallId,
error: {...reason, message: reason.message} error: {...reason, message: reason.message}
}) })
call.error = reason call.error = reason
call.end = Date.now() call.end = Date.now()
} }
)
) )
}) })