refactoring failures
This commit is contained in:
@@ -71,17 +71,17 @@ export default class Job extends events.EventEmitter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_failJob(job, msg = false) {
|
_failJob(job, output = false) {
|
||||||
this.debug(`Failing job ${job._id}`);
|
this.debug(`Failing job ${job._id}`);
|
||||||
|
|
||||||
|
const completedTime = moment().toISOString();
|
||||||
const doc = {
|
const doc = {
|
||||||
status: jobStatuses.JOB_STATUS_FAILED
|
status: jobStatuses.JOB_STATUS_FAILED,
|
||||||
|
completed_at: completedTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (msg) {
|
if (output) {
|
||||||
doc.output = {
|
doc.output = this._formatOutput(output);
|
||||||
content_type: 'text/plain',
|
|
||||||
content: msg
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.client.update({
|
return this.client.update({
|
||||||
@@ -97,12 +97,7 @@ export default class Job extends events.EventEmitter {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
_performJob(job) {
|
_formatOutput(output) {
|
||||||
this.debug(`Starting job ${job._id}`);
|
|
||||||
|
|
||||||
return Bluebird.fromCallback((cb) => this.workerFn(job._source.payload, cb))
|
|
||||||
.then((output) => {
|
|
||||||
const completedTime = moment().toISOString();
|
|
||||||
const unknownMime = false;
|
const unknownMime = false;
|
||||||
const docOutput = {};
|
const docOutput = {};
|
||||||
|
|
||||||
@@ -114,6 +109,19 @@ export default class Job extends events.EventEmitter {
|
|||||||
docOutput.content_type = unknownMime;
|
docOutput.content_type = unknownMime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return docOutput;
|
||||||
|
}
|
||||||
|
|
||||||
|
_performJob(job) {
|
||||||
|
this.debug(`Starting job ${job._id}`);
|
||||||
|
|
||||||
|
return Bluebird.fromCallback((cb) => this.workerFn(job._source.payload, cb))
|
||||||
|
.then((output) => {
|
||||||
|
this.debug(`Completed job ${job._id}`);
|
||||||
|
|
||||||
|
const completedTime = moment().toISOString();
|
||||||
|
const docOutput = this._formatOutput(output);
|
||||||
|
|
||||||
const doc = {
|
const doc = {
|
||||||
status: jobStatuses.JOB_STATUS_COMPLETED,
|
status: jobStatuses.JOB_STATUS_COMPLETED,
|
||||||
completed_at: completedTime,
|
completed_at: completedTime,
|
||||||
@@ -132,25 +140,14 @@ export default class Job extends events.EventEmitter {
|
|||||||
throw err;
|
throw err;
|
||||||
});
|
});
|
||||||
}, (jobErr) => {
|
}, (jobErr) => {
|
||||||
const completedTime = moment().toISOString();
|
this.debug(`Failure occurred during job ${job._id}`);
|
||||||
const doc = {
|
|
||||||
status: jobStatuses.JOB_STATUS_FAILED,
|
|
||||||
completed_at: completedTime,
|
|
||||||
output: {
|
|
||||||
content_type: false,
|
|
||||||
content: jobErr.toString()
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return this.client.update({
|
return this._failJob(job, jobErr.toString())
|
||||||
index: job._index,
|
|
||||||
type: job._type,
|
|
||||||
id: job._id,
|
|
||||||
version: job._version,
|
|
||||||
body: { doc }
|
|
||||||
})
|
|
||||||
.catch(() => false)
|
.catch(() => false)
|
||||||
.then(() => { throw jobErr; });
|
.then(() => {
|
||||||
|
this.emit('job_error', jobErr);
|
||||||
|
throw jobErr;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user