This episode is for members only

Sign up to access "Build a Livewire CSV Importer/Exporter" right now.

Get started
Already a member? Sign in to continue
Playing
19. Marking an import as complete

Transcript

00:00
Once again the process of importing is pretty much a duplicate of exporting so what we can do is once we queue this we can continue to chain on with our own jobs. So now we are going to mark
00:12
the import as complete once it goes through the process of reading each of these sheets, rows and importing them into our database. So we will go ahead and make out a job here, make a job and let's call this mark import complete now instead. So let's new this up, mark import complete and we want to pass through the import into here. Now of course what you can
00:37
also do as part of this you can also send an email when complete. So if you want to go ahead and add in a notification like we did for exports you can go ahead and add that in as well as well as absolutely any other jobs in here that you want. Let's go ahead and get this mark import complete. So this is an import model and let's change that over to import and we are going to
01:05
just touch the completed at date, super simple. So this import touch completed at and we should be good that's pretty much all we need to do. Let's try it out. So I'm going to go to the database and just get rid of all of these imports and I'm going to go and just start a new import here with these 10 records. So let's go ahead and click start import. We'll handle the closing of
01:30
this modal and redirecting over to imports as well but you can see sure enough that's complete and we know that this already works. So let's finish up by just going over to our import modal and handling what happens here and really it's just a redirect to the imports route although of course you can do absolutely anything there that you want. Okay so I'm going to try this out
01:54
with a slightly larger data set with the import just so we can see it hang around. Let's not do this with too many records otherwise we're going to end up with waiting for hours. Let's go ahead and truncate out our transactions. So let's truncate these transactions we've got nothing in here. Let's get rid of this import and let's get rid of these exports as well here. So we're going
02:15
to use our factory just to seed a bunch of data here. So let's say tinker and let's go ahead and say how many do we want to do. We know that this is 1,000 per batch so let's do 5,000 and let's bump this up to 10 actually so 10,000 transactions will generate. I'm going to go ahead and export these so let's export every single one of these. Obviously that is now pending. I'm just going to
02:44
wait for a few minutes for this to finish and then we'll go ahead and re-import it back into our database and while we're doing that we could also get rid of these two files in here as well. Okay let's just wait for this to finish and oh it's already done so let's go over I might have already deleted that no there it is. So let's re-import this now into our database after we
03:05
again truncate this out. So we're just making sure that this is handling slightly larger ones so let's go ahead and import this file which should import 10,000 records for us. You see how quick that was as well to read that CSV despite it being slightly larger it was very very quick to grab the count of records. That is already complete and there we go they're already in the database.

Episode summary

In this episode, we tackle marking an import as complete after it's processed. The process is pretty similar to how we handled exports, so if you've been following along, it should feel familiar! We'll set up a job that gets queued up after the import has run through all the sheets and rows and inserted them into the database.

First, we create a new job (called MarkImportComplete) that receives the import, and all it really needs to do is set the completed_at timestamp—super simple. We also touch on how you might want to send notifications or chain on other jobs when the import finishes, just like we did for exports.

After setting this up, we give it a test run! We'll clear out the imports and try importing a fresh batch of records to see everything works smoothly. We also handle some UI feedback: after the import, the user is redirected to the imports page, but you can tweak this however you like for your own project.

Finally, to make sure the system scales, we try it out with a larger dataset (10,000 records). We go through the full process: seed the database, export, clear things out, then re-import to make sure big imports are handled fast and efficiently. It all works great—and as you’ll see, even huge CSVs are processed super quickly!

Episode discussion

No comments, yet. Be the first!