Skip to main content

"Background" Tasks: Dispatch Jobs into Queue

Premium
3:27

The Full Lesson is Only for Premium Members

Want to access all of our courses? (36 h 00 min)

You also get:

61 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

F_r avatar

thanks for the video. I understand the fact That you move the sub-creation into a job class. but whow to make that everything Was created in by the job for that particular user un maybe return to the user an appropriate message.

And when we have these many related creation step in db, is it no a good idea of put them all in a DB transaction ?

👍 1
Jessica Oliveira avatar

I struggle with that also. I am looking forward to his response 🥸

Povilas Korop avatar

Hi Jessica and Frank, If the job takes longer and you want to return a successful message afterwards, you may send an EMAIL with success message, or use websockets with Soketi to wait for it to finish, see my article: WebSockets in Laravel with Soketi: Real-Time Updates Example

Regarding DB transaction - yes, it's probably a good idea if you have a chance that some of those operations may fail.

Pablo Zagni avatar

Something like public function handle() { Log::info('ImportController.asientosPost: START'); $array = FacadesExcel::toArray(new AsientosImport, $this->filename );
[...] Log::info('ImportController.asientosPost: EMAIL'); $user = User::find($this->user_id); $user->notify(new ImportAsientosFinished( $this->desde, $this->hasta )); Log::info('ImportController.asientosPost: END'); }

marcelo-kazalukian avatar

Hello, What do you think put the line NewUserDataJob::dispatch($user); inside of the Service/Action class? So we can have everything in one place. I see this advantange: that store method is part of one of the controllers for web.php for instance, then when you try to implement the store method in the api.php you have everything in one place adn avoid the posibility of copy a group on lines.

Modestas avatar

You can definitely do that! And it is a smart idea, as soon as you have multiple entry ways :)

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.