Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
fabpot merged 1 commit intosymfony:5.4fromlyrixx:worker-stop
Jul 3, 2021
Merged

Conversation

@lyrixx
Copy link
Member

@lyrixxlyrixx commentedDec 23, 2020
edited
Loading

QA
Branch?5.4
Bug fix?no
New feature?yes
Deprecations?no
TicketsFix#39491
LicenseMIT
Doc PR

Copy link
Member

@jderussejderusse left a 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
Copy link
MemberAuthor

lyrixx commentedDec 23, 2020
edited
Loading

I'd rather use an interface to let people add behavior on existing Exception (like we do with
UnrecoverableExceptionInterface)

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

We already have a mechanism to stop the worker using eventDispatcher.

Yes I know, but this is more complex IMHO. Having something native is way more efficient
And BTW, 2 people already asked me how do to that :) And the issue receive a good feedback.

@jderusse
Copy link
Member

but what could you add to the Exception?

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);}

@chalasr
Copy link
Member

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.
I agree that hooking into worker lifecycle events sounds better from a design pov.
Adding a sample listener to the docs like the one showed by@jderusse may be enough to fix this issue and could avoid having several paths for the same goal.

@lyrixx
Copy link
MemberAuthor

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.

@nicolas-grekasnicolas-grekas added this to the5.x milestoneDec 28, 2020
@lyrixxlyrixxforce-pushed theworker-stop branch 2 times, most recently fromae59fa0 to2b8f6c2CompareDecember 31, 2020 15:47
@lyrixx
Copy link
MemberAuthor

lyrixx commentedDec 31, 2020
edited
Loading

  • I added an interface
  • the system uses the Event Dispatch

Copy link
Contributor

@ottavianoottaviano left a comment
edited
Loading

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;}

@lyrixx
Copy link
MemberAuthor

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

andrewmy reacted with hooray emoji

@fabpot
Copy link
Member

Thank you@lyrixx.

ottaviano reacted with hooray emoji

@fabpotfabpot merged commitb28b63c intosymfony:5.4Jul 3, 2021
@lyrixxlyrixx deleted the worker-stop branchJuly 5, 2021 08:26
This was referencedNov 5, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@srozesrozeAwaiting requested review from sroze

@jderussejderusseAwaiting requested review from jderusse

@OskarStarkOskarStarkAwaiting requested review from OskarStark

+1 more reviewer

@ottavianoottavianoottaviano approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

5.4

Development

Successfully merging this pull request may close these issues.

[RFC][Messenger] allow to shutdown worker "consume" with a particular Exception

8 participants

@lyrixx@jderusse@chalasr@fabpot@OskarStark@ottaviano@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp