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

[Workflow] Add transition completed event#22587

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
lyrixx merged 1 commit intosymfony:3.4fromizzyp:patch-2
Aug 7, 2017
Merged

Conversation

@izzyp
Copy link
Contributor

@izzypizzyp commentedApr 30, 2017
edited by lyrixx
Loading

QA
Branch?3.4
Bug fix?yes
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PRsymfony/symfony-docs#8213

Because the "entered" event is the only event dispatched after the new marking is applied, and publish's an event upon entering into a "Place" (as opposed to completing a transition), it is not sufficient for a lot of use cases and is causing bugs.

Example:
Enabled Transitions:

  1. A -> B
  2. B -> C
  3. C -> B

Transition 1 and transition 3, will dispatch an "entered" event on Place B, forcing post transition behaviour to be the same for both transition 1 and 3.

A user might need different behaviour depending on the transition, rather the the destination.
A concrete use case would be when applying an "undo" transition to a subject. One may or may not want to re-trigger all the events associated with the original transition to that Place.

I propose adding a "completed" event (ie. Transition completed) in addition to the entered event.

@izzypizzyp changed the titleAdd transition completed event[Workflow] Add transition completed eventApr 30, 2017
@xabbuh
Copy link
Member

I am not convinced that we really need this additional event. You can already make use of the entered event and retrieve the applied transition from theEvent object.

@izzyp
Copy link
ContributorAuthor

izzyp commentedApr 30, 2017
edited
Loading

Are you suggesting that in the EventSubscriber->getSubscribedEvents() you would subscribe to an event like so:

$events = [    'workflow.workflow_name.entered.place_name'         => 'onEnteredPlaceName',    ...]

and in theonEnteredPlaceName() method you would check and apply logic depending on the transition passed with the event?

like so:

if ($event->getTransition()->getName() == 'draft') {some stuff ...}elseif ($event->getTransition()->getName() == 'undo') {some other stuff ...}etc...

This doesn't seem right to me at all. It forces unrelated logic into the same listener methods, the listeners become responsible for knowing which transitions are being called, etc.

It is much cleaner and simpler to dispatch a completed transition event.

The Entered event relates to the place, the Completed event relates to the transition. They serve different purposes.

@nicolas-grekasnicolas-grekas added this to the3.4 milestoneMay 2, 2017
@nicolas-grekasnicolas-grekas changed the base branch frommaster to3.4May 23, 2017 17:02
@Padam87
Copy link
Contributor

Huge 👍 on this.@izzyp gave a very good use case, this is very useful for circular state machines. I had the same problem recently.

I have solved this by checking the transition name as@xabbuh suggested, but it would be nice to be able to tie this to transition complete event.

@nicolas-grekas
Copy link
Member

ping@lyrixx@Nyholm

@Nyholm
Copy link
Member

Thank you for the ping.

Thank you@izzyp for this suggestion. Can you tell me how this differ from the "annouce" event? I fail to see any difference. But maybe you see something I don't.
Also, be aware,master Workflow is a bit updated from where you based you PR.

@Padam87
Copy link
Contributor

Padam87 commentedJul 19, 2017
edited
Loading

@Nyholm The announce event is for the next available transitions after the event is complete. This one is for the just completed event.

For example:
A -> B
B -> C
C -> B

Applying the A->B transition triggers the events, but none of them are right for this:

  • enter/entered : Refers to the state, instead of the transition, and in this case multiple transitions can move the state to B.
  • announce: Refers to the next available transitions. B->C in this case.
  • completed: Refers to the just completed transition A->B

I understand the reluctance to add a new event yet again, but keep in mind that state machines usually have events for transitions, not states, due to their circular nature. This is not necessarily true for workflows.
Since Symfony supports both, it should have events for both.

@Nyholm
Copy link
Member

Thank you. I understand better now.

If applying the A->B transition triggers the events in your example, You wound get:

  • workflow.foo.leave.a
  • workflow.foo.transition.ab_transition
  • workflow.foo.enter.b
  • workflow.foo.entered.b
  • workflow.foo.completed.ab_transition
  • workflow.foo.announce.bc_transition
  • a lot of other related (less detailed) events.

I can understand why you want the new event. I do not think we needworkflow.foo.completed andworkflow.foo.completed because they exact copies of the "announce" (and "entered"!) events.

I would (but Im not sure the other agree) modify theannounce() function and add your one new event there. Maybe even rename it toworkflow.foo.completed_transaction.ab_transition

@Padam87
Copy link
Contributor

Padam87 commentedJul 19, 2017
edited
Loading

As I understandannounce only meant to announce new possibilities.
A->B is complete (new event here: complete.A->B), now you can apply the B->C transition (announce.B->C).

announce is very useful when you want to auto apply a transition. I use this for billing. When the billing conditions are met, apply thebill transition which creates an invoice.

I see these as totally different events, for different use cases.enter andentered refer to the state,announce refers to future transitions,complete would refer to the current transition.

@lyrixx
Copy link
Member

Hello. (Sorry for the delay.)

I understand clearly why others event are not suitable for you but right now I fail to see a real use case for this event. Could you (you or@Padam87) tell us more about what you will do in your listener?

Thanks

(note: I'm OK with this PR, I just be sure we really need theses events)

@lyrixx
Copy link
Member

Oh, And you need to update the CHANGELOG also.
Thanks.

@Padam87
Copy link
Contributor

At printmagus.com (online printing shop) I have recently replaced finite with the new workflow component. I was glad to see that it was an easy swap, just this one issue, with 4 occurrences.

files state machine:
files

Theuploaded state can be reached by 2 transitions:upload andrecheck.
upload listener does the following:

  • calculates the deadline for the order (deadlines start when the files are uploaded)
  • sends an email confirming the upload and the new deadline
  • emits a message to our WS, notifying the team about the new file ready for preflight

recheck on the other hand:

  • removes any comments about the files
  • removes preflight data
    (basically resets the validation process)

I hope this is enough, the other 3 cases I have are part of ourproduction state machine with 19 states and 30 something transitions, and I don't want a headache right now :D

@lyrixx
Copy link
Member

👍

@izzyp
Copy link
ContributorAuthor

@Nyholm@lyrixx

The uses outlined by@Padam87 are spot on.

I have many different use cases in my projects that this is indispensable for. The simplest example i can think of is as follows:

An application process follows this workflow:

screen shot 2017-07-21 at 13 19 40

We listen for the "workflow.foo.completed.approve" event - and for example send an email to the applicant requesting "further info" amongst other actions.

If the applicant doesn't respond within a certain amount of time, the cancel transition is applied.

If the applicant responds after the application is already cancelled - we apply the reapprove transition to the application and listen for the "workflow.foo.completed.reapprove" event. For this transition to Approve, we do not need to resend the "further info" email or trigger the other actions that were raised on the original approval, the actions raised in this case are different.

Bottom line - same place is Entered but via 2 (or more) different Transitions and each different transition needs to trigger different behaviour and actions, even though they end in the same Place.

@lyrixx
Copy link
Member

@izzyp Don't worry I'm gonna merge this PR ;) I already added a 👍

I'm just waiting for the CHANGELOG and for the fabbot fix

@xabbuh
Copy link
Member

@izzyp Looks like something went wrong while rebasing. Did you rebase onmaster instead of3.4?

@lyrixx
Copy link
Member

@izzyp I can finish this PR for you if you lake time, just tell me;)

@izzyp
Copy link
ContributorAuthor

Thanks@lyrixx

I buggered something up while attempting to rebase and i've been too swamped for time to work out what i did wrong or how to fix.

Would appreciate any assistance to get this finished up!

@lyrixx
Copy link
Member

Here we go. I cleaned the git history (was not easy, I don't know what you did ;) ) and I updated the PR description.


👍

@izzyp
Copy link
ContributorAuthor

Thanks@lyrixx !

@lyrixx
Copy link
Member

Failures on appveyor seems not related.

@lyrixx
Copy link
Member

It took time, but here we go, this is in now. Thank you very much@izzyp.

@lyrixxlyrixx merged commitc254cac intosymfony:3.4Aug 7, 2017
lyrixx added a commit that referenced this pull requestAug 7, 2017
This PR was merged into the 3.4 branch.Discussion----------[Workflow] Add transition completed event| Q             | A| ------------- | ---| Branch?       | 3.4| Bug fix?      | yes| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR |symfony/symfony-docs#8213---Because the "entered" event is the only event dispatched after the new marking is applied, and publish's an event upon entering into a "Place" (as opposed to completing a transition), it is not sufficient for a lot of use cases and is causing bugs.Example:Enabled Transitions:1. A -> B2. B -> C3. C -> BTransition 1 and transition 3, will dispatch an "entered" event on Place B, forcing post transition behaviour to be the same for both transition 1 and 3.A user might need different behaviour depending on the transition, rather the the destination.A concrete use case would be when applying an "undo" transition to a subject. One may or may not want to re-trigger all the events associated with the original transition to that Place.I propose adding a "completed" event (ie. Transition completed) in addition to the entered event.Commits-------c254cac [Workflow] Added an transition completed event
This was referencedOct 18, 2017
@GuiteGuite mentioned this pull requestDec 13, 2017
17 tasks
javiereguiluz pushed a commit to symfony/symfony-docs that referenced this pull requestJan 10, 2018
javiereguiluz added a commit to symfony/symfony-docs that referenced this pull requestJan 10, 2018
…zzyp)This PR was submitted for the master branch but it was merged into the 3.4 branch instead (closes#8213).Discussion----------[Workflow] Document the new transition completed eventas per PR -symfony/symfony#22587Commits-------b8249ab [Workflow] Document the new transition completed event
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@lyrixxlyrixxlyrixx approved these changes

@xabbuhxabbuhxabbuh approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

3.4

Development

Successfully merging this pull request may close these issues.

7 participants

@izzyp@xabbuh@Padam87@nicolas-grekas@Nyholm@lyrixx@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp