laravel-excel-export-import-example icon indicating copy to clipboard operation
laravel-excel-export-import-example copied to clipboard

Catch an error while importing huge CSV in queue using laravel excel

Open shashankdevstree opened this issue 3 years ago • 5 comments

I am using ShouldQueue method to have the large CSV into Queue but the errors of validations I am not able to catch them!

public function registerEvents(): array { return [ ImportFailed::class => function(ImportFailed $event) { dd($event); // This I will write into the FILE or send EMAIL but the job runs successfully but validation errors keep empty. $this->importedBy->notify(new ImportHasFailedNotification); }, ]; }

My code looks like below...

public function registerEvents(): array { return [ ImportFailed::class => function(ImportFailed $event) { $filename = public_path('tmp').'/validation_error.txt'; $myfile = fopen($filename, "w"); fwrite($myfile, "domo"); fclose($myfile); }, ]; }

I am in hope that if there is any error validation_error.txt file will have "Demo" inside it.

I just wanted to add those errors in a file and email to the user that's it.

Also, I have crossed verify by removing ShouldQueue it gives me proper errors for email already exists a kind of.

Please help if you have any ideas! Thanks!

shashankdevstree avatar Dec 06 '21 02:12 shashankdevstree

hi do you have find any soultion for this ? please share the code with me.....

animeshs-reconnectin avatar Apr 21 '22 04:04 animeshs-reconnectin

Hello @animeshs-reconnectin ,

Sad, you are also suffering from this. Actually, I uninstall this package and handle it manually. I have used the laravel queue for importing the huge CSV and maintained one different CSV for importing validation errors in it.

What I have done is I have created separate chunks of array let's say 1000 then 2 chunks of 500 records validate it using laravel standard method whatever validation errors I am getting I have dumped into validation error CSV.

Now, I set this process into the laravel queue so it will process 500 records each and append the validation errors.

Then after I checked into jobs table if there are any jobs left based on the name of the job if not then send a validation error CSV to the client that the process has been completed successfully.

Hope this helps and let me know if you need further help. thanks!

shashankdevstree avatar Apr 21 '22 06:04 shashankdevstree

ok thank you @shashankdevstree can you please share you code it will be really helpful for me (if you have it)

animeshs-reconnectin avatar Apr 21 '22 08:04 animeshs-reconnectin

sorry, but I can not share the code if you need an idea I can help you with that.

shashankdevstree avatar Apr 21 '22 09:04 shashankdevstree

@shashankdevstree its ok thanks

animeshs-reconnectin avatar Apr 21 '22 09:04 animeshs-reconnectin