vendredi 29 novembre 2019

How can I ensure that multiple Laravel Listeners for the same event are executed and finished before starting the next one?

I have a Laravel 5.7 (with PHP 7.2) application that uses events and listeners with Redis queues. I have some workers that consume the queue and execute the listeners.

this is my event and listeners interaction in the EventServiceProvider class:

protected $listen = [
    SavedObject::class => [
        Listener1::class,
        Listener2::class,
        Listener3::class,
    ],
];

My problem is that I need that Listener2 executes and finishes before Listener3 is even executed. Laravel ensures that the listeners are executed in order, but if I have multiple workers, the Listener2 is executed and before it's finished, another worker executes Listener3 and it ruins everything.

How can I ensure that Listener2 finishes before starting Listener3 execution? Maybe a way to execute all of the Listeners of the same event using the same worker to ensure that?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2OVsACi
via IFTTT

Aucun commentaire:

Enregistrer un commentaire