From 8e8609eede9fe4ea5697afe162676d0cf503bb90 Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Tue, 12 Jul 2016 11:14:58 -0700 Subject: [PATCH] always emit job failure event --- src/worker.js | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/worker.js b/src/worker.js index 4ef9dbe..57f67b8 100644 --- a/src/worker.js +++ b/src/worker.js @@ -117,6 +117,12 @@ export default class Job extends events.EventEmitter { output: docOutput }; + this.emit(constants.EVENT_WORKER_JOB_FAIL, { + job: formatJobObject(job), + worker: this.toJSON(), + output: docOutput, + }); + return this.client.update({ index: job._index, type: job._type, @@ -124,16 +130,7 @@ export default class Job extends events.EventEmitter { version: job._version, body: { doc } }) - .then(() => { - const eventOutput = { - job: formatJobObject(job), - worker: this.toJSON(), - output: docOutput, - }; - - this.emit(constants.EVENT_WORKER_JOB_FAIL, eventOutput); - return true; - }) + .then(() => true) .catch((err) => { if (err.statusCode === 409) return true; this.debug(`_failJob failed to update job ${job._id}`, err);