Thursday, March 16, 2017

Difference between Laravel queued event listener vs jobs

I'm trying to wrap my head around Laravel queued event listener https://laravel.com/docs/5.4/events#queued-event-listeners vs jobs https://laravel.com/docs/5.4/queues#creating-jobs.

It seems to me that both are very similar 1. Both utilises ShouldQueue interface (in the case of event listener, this is an option) 2. Both implements the handle and failed (optional) method to perform their respective tasks.

Essentially, to me both are queued items that can be run asynchronously.

What I am able to distinguish so far is that jobs have more 'advanced' features/configurations like $timeout, $tries properties and you may also delay the 'trigger' of a job (courtesy of the Illuminate\Bus\Queueable trait). There are more I'm sure, but I'm pointing out the one that pops out to me.

So, the question is - what's the actual difference between the two and more importantly, when do you choose/favour one over the other?

Cheers!



via LC Yoong

Advertisement