In this episode, we focus on how to mark an import as complete after all jobs in a batch have finished. We start by discussing how it's easy to track rows inserted within each import CSV job, but it's a bit trickier to know exactly when the whole batch of jobs is done.
To solve this, we take advantage of the finally
callback available on the batch. This callback lets us run some code once all jobs in the batch have successfully completed. In our case, we use this to update the import record in the database, setting it as completed. You can either do this by updating a specific field or simply "touching" a timestamp field like completed_at
. This helps us keep track of which imports are fully processed.
We also touch on other possible callbacks you can add, such as ones for handling failed jobs, though we don't go deep into that here.
Finally, you'll see a quick demo of uploading a file and running through the import process. At the end, once the batch has finished processing, you can see the import marked as complete with the proper timestamp in the database. It's a straightforward step, but really helpful for keeping your data in sync!