Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Events not working for me #94

Closed
juliangums opened this issue Apr 21, 2024 · 3 comments
Closed

Events not working for me #94

juliangums opened this issue Apr 21, 2024 · 3 comments

Comments

@juliangums
Copy link

I have a state machine workflow and I defined a listener with some events for it but I can't get them to work. I found this in the readme:
// Specifies events to dispatch (only in 'workflow', not 'state_machine')

Does this mean there are no events for state machines? How can I make them work? I do need additional guard logic etc on them.

@juliangums
Copy link
Author

I didn't register the subscriber class in a service provider. This sorted it:

    public function boot(): void
    {
        Event::subscribe(WorkflowSubscriber::class);
    }

Don't quite understand what the above sentence means, then. Does it mean state machines always fire all events?

@zerodahero
Copy link
Owner

This is a specific Symfony Workflow feature. The full comment should offer some more context:

// Specifies events to dispatch (only in 'workflow', not 'state_machine')
// - set `null` to dispatch all events (default, if omitted)
// - set to empty array (`[]`) to dispatch no events
// - set to array of events to dispatch only specific events
// Note that announce will dispatch a guard event on the next transition
// (if announce isn't dispatched the next transition won't guard until checked/applied)
'events_to_dispatch' => [ ... ]

The feature in the Symfony workflow is discussed more in-depth here: https://symfony.com/doc/current/workflow.html#choosing-which-events-to-dispatch

And, for state machines, it looks like that feature wasn't supported properly in the component itself when that was originally written to this package, but has since been updated/fixed (see upstream commit, here). If you need to specify which events are dispatched for a state machine, we'll need to add that in to this package (should be only a couple line change, if that).

So, yes, you are correct in that state machines currently fire all events.

Did that help clarify things?

@juliangums
Copy link
Author

Yes, that clarifies it. I did get it to work but for some reason after some time it froze the whole application or filled up memory. I ended up removing the event listener adding all the guard logic into policies instead

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants