Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Messenger] Added StopWorkerException#39623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
src/Symfony/Component/Messenger/Exception/StopWorkerException.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
jderusse left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
I'd rather use an interface to let people add behavior on existing Exception (like we do with
UnrecoverableExceptionInterface)
We already have a mechanism to stop the worker using eventDispatcher.
This can be used at userland to achieve the same behavior.
class StopWorkerOnCustomLogicListenerimplements EventSubscriberInterface{private$run =true;publicfunctiononMessageFailed(WorkerMessageFailedEvent$event):void {if ($event->getThrowable()instanceof Whatever) {$this->run =false; } }publicfunctiononWorkerRunning(WorkerRunningEvent$event):void {if (!$event->isWorkerIdle() && !$this->run) {$this->run =true;$event->getWorker()->stop(); } }publicstaticfunctiongetSubscribedEvents():array {return [ WorkerMessageFailedEvent::class =>'onMessageFailed', WorkerRunningEvent::class =>'onWorkerRunning', ]; }}
lyrixx commentedDec 23, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
I dont follow you, I could create an interface, and implementing it, but what could you add to the Exception? I'll not used anyway
Yes I know, but this is more complex IMHO. Having something native is way more efficient |
jderusse commentedDec 23, 2020
hmm.. nothing, It's just a Marker interface interface StopWorkerExceptionInterfaceextends \Throwable{}class StopWorkerExceptionextends RuntimeExceptionimplements StopWorkerExceptionInterface{}if ($throwableinstanceof StopWorkerExceptionInterface) {$this->stop();} That would allow people use class MyBusinessExceptionimplements StopWorkerExceptionInterface {} Instead of try {}catch (MyBusinessException$e) {thrownewStopWorkerExceptionInterface(??, ??,$e);} |
Uh oh!
There was an error while loading.Please reload this page.
chalasr commentedDec 23, 2020
I see how much this can be handy and simple, but throwing such an exception from e.g. a message handler feels weird to me. Stopping the worker is a consequence of an error, not an error on its own. |
lyrixx commentedDec 28, 2020
I agree this PR could leverage the Event Dispatcher System. But messenger could work without messenger, so the exception would become useless... But I think we don't care. But IMHO this should not be a doc cookbook. The proposed system is really hackish. Many (good) developers did not find it by them-self. Let's add a native / simple behavior here. |
ae59fa0 to2b8f6c2Comparelyrixx commentedDec 31, 2020 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
|
ottaviano left a comment• edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
should not we changeHandleMessageMiddleware instead and avoid to add one listener:
up: ok, I saw that it was the previous version 👌
}catch (\Throwable$e) {if ($einstanceof StopWorkerExceptionInterface) {throw$e; }$exceptions[] =$e;}
src/Symfony/Component/Messenger/EventListener/StopWorkerOnCustomStopExceptionListener.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
lyrixx commentedMay 10, 2021
I have rebased this PR and added some tests. There are 9 👍🏼 on the issue, so I do think we should consider to merge this PR |
fabpot commentedJul 3, 2021
Thank you@lyrixx. |
Uh oh!
There was an error while loading.Please reload this page.