fix code and tests, use custom errors
This commit is contained in:
@@ -178,7 +178,7 @@ export default class Worker extends events.EventEmitter {
|
|||||||
if (isResolved) return;
|
if (isResolved) return;
|
||||||
|
|
||||||
this.debug(`Timeout processing job ${job._id}`);
|
this.debug(`Timeout processing job ${job._id}`);
|
||||||
reject(new WorkerTimeoutError({
|
reject(new WorkerTimeoutError(`Worker timed out, timeout = ${job._source.timeout}`, {
|
||||||
timeout: job._source.timeout,
|
timeout: job._source.timeout,
|
||||||
jobId: job._id,
|
jobId: job._id,
|
||||||
}));
|
}));
|
||||||
@@ -220,16 +220,24 @@ export default class Worker extends events.EventEmitter {
|
|||||||
});
|
});
|
||||||
}, (jobErr) => {
|
}, (jobErr) => {
|
||||||
if (!jobErr) {
|
if (!jobErr) {
|
||||||
jobErr = new UnspecifiedWorkerError({
|
jobErr = new UnspecifiedWorkerError('Unspecified worker error', {
|
||||||
jobId: job._id,
|
jobId: job._id,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// job execution failed
|
// job execution failed
|
||||||
if (jobErr.type === 'WorkerTimeoutError') {
|
if (jobErr.name === 'WorkerTimeoutError') {
|
||||||
this.debug(`Timeout on job ${job._id}`);
|
this.debug(`Timeout on job ${job._id}`);
|
||||||
this.emit(constants.EVENT_WORKER_JOB_TIMEOUT, this._formatErrorParams(jobErr, job));
|
this.emit(constants.EVENT_WORKER_JOB_TIMEOUT, this._formatErrorParams(jobErr, job));
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
// append the jobId to the error
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
Object.assign(jobErr, { jobId: job._id });
|
||||||
|
} catch (e) {
|
||||||
|
// do nothing if jobId can not be appended
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.debug(`Failure occurred on job ${job._id}`, jobErr);
|
this.debug(`Failure occurred on job ${job._id}`, jobErr);
|
||||||
|
|||||||
@@ -719,7 +719,7 @@ describe('Worker class', function () {
|
|||||||
expect(err).to.have.property('error');
|
expect(err).to.have.property('error');
|
||||||
expect(err).to.have.property('job');
|
expect(err).to.have.property('job');
|
||||||
expect(err).to.have.property('worker');
|
expect(err).to.have.property('worker');
|
||||||
expect(err.error).to.have.property('type', 'UnspecifiedWorkerError');
|
expect(err.error).to.have.property('name', 'UnspecifiedWorkerError');
|
||||||
done();
|
done();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
done(e);
|
done(e);
|
||||||
@@ -776,7 +776,7 @@ describe('Worker class', function () {
|
|||||||
expect(err).to.have.property('error');
|
expect(err).to.have.property('error');
|
||||||
expect(err).to.have.property('job');
|
expect(err).to.have.property('job');
|
||||||
expect(err).to.have.property('worker');
|
expect(err).to.have.property('worker');
|
||||||
expect(err.error).to.have.property('type', 'WorkerTimeoutError');
|
expect(err.error).to.have.property('name', 'WorkerTimeoutError');
|
||||||
done();
|
done();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
done(e);
|
done(e);
|
||||||
|
|||||||
Reference in New Issue
Block a user