WorkerPool icon indicating copy to clipboard operation
WorkerPool copied to clipboard

catch workerException

Open TechAlchemistry opened this issue 9 years ago • 3 comments

Will be good if we can catch of the worker exceptions. For example:

$wp = new WorkerPool();
$wp->onWorkerException(function(\Exception $ex, Worker $worker) {
   // there we can handle the exception (logging, restart the task or other)
});

TechAlchemistry avatar Oct 29 '16 09:10 TechAlchemistry

The fun part is that you need to serialize exceptions in order to send them via the pipe. Just did this myself. Any ressource or object anywhere either directly as a function parameter or in some nested array/object hierarchy will make the serialization fail. so you will have to iterate recursively through the stack and the objects to remove any non-serializable data. And as objects are references only you will modify the state of your worker. Really funny is PDO which implements __sleep() and just throws an error.

eazrael avatar Nov 09 '19 00:11 eazrael

You get already the stacktrace as string as well as the message as return result. We avoid serializing the whole stack by serializing the string stack trace only.

qxsch avatar Nov 09 '19 11:11 qxsch

Leaving this ticket open. Until anyone comes with a good serialization logic.

qxsch avatar Nov 09 '19 11:11 qxsch