kue icon indicating copy to clipboard operation
kue copied to clipboard

Failed jobs should be able to return an object in the job callback

Open andrewtamura opened this issue 11 years ago • 6 comments

When failing a job by passing a parameter into the first argument of the done() callback, this object usually gets converted to a string. It would offer more flexibility to the pass back the object without calling toString().

Here is the code that converts the error parameter into a string https://github.com/Automattic/kue/blob/master/lib/queue/worker.js#L126

Passing an object on success does not get converted, see https://github.com/Automattic/kue/blob/master/lib/queue/worker.js#L193

As a workaround, one can fail a jobs like this in order to get an object passed back

done({message: {foo:'bar'}});

andrewtamura avatar Jun 06 '15 01:06 andrewtamura

+1

bradvogel avatar Jun 06 '15 04:06 bradvogel

It would be very handy to be able to pass the error object through, as on the producer side of things, I subscribe to a job once it's been created, and then act upon the result back, and only being able to in effect put a string into the error back is a little limiting.

I did a similar workaround to Andrew, except I found that his way, the error object is not maintained and cannot be seen in the GUI, so I simply JSON.stringify an object into the err.message then parse it back out on the producer side.

dandanknight avatar Aug 19 '15 09:08 dandanknight

+1

Trindaz avatar Dec 18 '15 21:12 Trindaz

+1

niklassletteland avatar Jan 15 '16 19:01 niklassletteland

A PR would be welcome...

behrad avatar Jan 15 '16 20:01 behrad

+1

maZahaca avatar Apr 13 '16 22:04 maZahaca