Courses

How to Structure Laravel 9 Projects

"Background" Tasks: Dispatch Jobs into Queue

Previous: Repositories: Why NOT to Use Them?
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
avatar

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

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.

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'); }

avatar
You can use Markdown
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.

avatar

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

avatar
You can use Markdown
avatar
You can use Markdown