Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
shashankdevstree opened this issue Dec 6, 2021 · 5 comments

Comments

@shashankdevstree
Copy link

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!

@animeshs-reconnectin
Copy link

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

@shashankdevstree
Copy link
Author

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!

@animeshs-reconnectin
Copy link

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

@shashankdevstree
Copy link
Author

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

@animeshs-reconnectin
Copy link

@shashankdevstree its ok
thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants