Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

Commit

Permalink
Events: enable class names and return jobdata
Browse files Browse the repository at this point in the history
If the handler is an ES6 Class, return `handler.constructor.name` instead of `handler.type` in events.
In the `job.handled` event, return the jobdata as the second parameter.
  • Loading branch information
maktouch authored Nov 7, 2017
1 parent 1849d02 commit 6c69156
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,21 @@ FiveBeansWorker.prototype.doWork = function doWork(handler, jobID, jobdata)
var start = new Date().getTime();
this.currentJob = jobID;
this.currentHandler = handler;
var handlerName = (function(handler) {
if (handler.constructor && handler.constructor.name) {
return handler.constructor.name;
}

return handler.type;
})(handler);

try
{
handler.work(jobdata, function(action, delay)
{
var elapsed = new Date().getTime() - start;

self.emit('job.handled', { id: jobID, type: handler.type, elapsed: elapsed, action: action });
self.emit('job.handled', { id: jobID, type: handlerName, elapsed: elapsed, action: action }, jobdata);

switch (action)
{
Expand All @@ -246,7 +253,7 @@ FiveBeansWorker.prototype.doWork = function doWork(handler, jobID, jobdata)
}
catch (e)
{
self.emitWarning({ message: 'exception in job handler', id: jobID, handler: handler.type, error: e });
self.emitWarning({ message: 'exception in job handler', id: jobID, handler: handlerName, error: e });
self.buryAndMoveOn(jobID);
}
};
Expand Down

0 comments on commit 6c69156

Please sign in to comment.