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
10. Marking the export as complete

Transcript

00:00
Because we are queuing our export now, what we can do is add on to the export chain. By that I mean we can just push on any new jobs that we want to follow on from the export process. To do this we use the chain method and we just pass an array of any jobs that we want to push on.
00:20
So let's go ahead and add in a job to mark this export as complete, which we know over in the database is this complete at that column. I'm just going to get rid of what we have in here so far. And just to keep things nice and tidy let's get rid of both of these as well.
00:37
Okay so what do we want to do here? Well we want to create out a new job, so our own custom job now that we can push. And we're going to call this mark export complete. We'll create one for imports as well a little bit later.
00:52
Okay so let's new this up, so new mark export complete. And what do we want to pass into here? Well we want to pass the export itself because that's what we need this to be aware of. And of course we need to actually update this model.
01:05
So over in the constructor for this job let's go ahead and put in that export. And there we go, so under handle all we really need to do here now is say this export and touch completed at. That will push the current timestamp, current date and time to that column.
01:26
And before we forget let's go over to our export model and let's just make sure we have the completed at cast here to a date time. And we should be good. Okay let's go ahead and just export out 10 or so of these records just to check this out.
01:48
And we know that over here completed at should be filled once this export process has finished. So let's go over to the database and yeah sure enough completed at has finished and it has been filled in. Now obviously this was very quick but the longer the process the longer this is going to take.
02:06
And we can actually use this completed at column a little bit later to show a status when we list out all of the exports that we're waiting for. Let's head over to the next episode though and create out another thing that we can push into this chain which is alerting the user by email when the export is complete.

Episode summary

In this episode, we dive into enhancing our export process by marking exports as complete once they've finished processing. We start by looking at how we're using job queues and how we can chain additional jobs to run after the export job completes.

We implement a custom job called MarkExportComplete that updates the completed_at column in the database for the finished export. This involves passing the export model into the job, updating the completed_at timestamp, and making sure our model casts this column as a datetime.

To verify everything works, we run an export of a handful of records and then check the database to confirm that the completed_at column is being properly filled in when the export finishes. This sets us up nicely for future episodes, where we'll use this column to display the status of exports and even trigger email notifications to users when their exports are done.

Stay tuned for the next episode, where we'll add another job to the chain to email the user when an export completes!

Episode discussion

No comments, yet. Be the first!