From 3b8127874bd44604c0b5cebec78abec1b704712b Mon Sep 17 00:00:00 2001 From: Joe Fleming Date: Fri, 29 Apr 2016 17:15:29 -0700 Subject: [PATCH] only send attempt message if no output always append failure message if one exists --- src/worker.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/worker.js b/src/worker.js index f4d6191..04dbf15 100644 --- a/src/worker.js +++ b/src/worker.js @@ -41,7 +41,8 @@ export default class Job extends events.EventEmitter { const attempts = job._source.attempts + 1; if (attempts > job._source.max_attempts) { - return this._failJob(job, `Max attempts reached (${job._source.max_attempts})`) + const msg = (!job._source.output) ? `Max attempts reached (${job._source.max_attempts})` : false; + return this._failJob(job, msg) .then(() => false); } @@ -70,13 +71,13 @@ export default class Job extends events.EventEmitter { }); } - _failJob(job, msg) { + _failJob(job, msg = false) { this.debug(`Failing job ${job._id}`); const doc = { status: jobStatuses.JOB_STATUS_FAILED }; - if (!job._source.output) { + if (msg) { doc.output = { content_type: 'text/plain', content: msg @@ -91,7 +92,7 @@ export default class Job extends events.EventEmitter { body: { doc } }) .catch((err) => { - if (err.statusCode === 409) return false; + if (err.statusCode === 409) return true; throw err; }); }