@@ -149,6 +149,7 @@ def handle(self, *args, **options):
149149 if not dry_run :
150150 # Create events with preserved timestamps from original instances
151151 event_records = []
152+ failed_records = []
152153 for instance in filtered_batch :
153154 try :
154155 # Create event record with all model fields
@@ -184,10 +185,12 @@ def handle(self, *args, **options):
184185 event_records .append (EventModel (** event_data ))
185186
186187 except Exception as e :
188+ failed_records .append (instance .id )
187189 logger .error (
188190 f"Failed to prepare event for { model_name } "
189191 f"ID { instance .id } : { e } " ,
190192 )
193+ # Continue processing other records in the batch
191194
192195 # Bulk create all events in this batch
193196 if event_records :
@@ -218,34 +221,49 @@ def handle(self, *args, **options):
218221 # Re-raise the exception instead of falling back
219222 raise
220223
221- processed += len (filtered_batch )
224+ # Count only successfully processed records
225+ successful_in_batch = len (event_records )
226+ failed_in_batch = len (failed_records )
227+ processed += successful_in_batch
228+
229+ if failed_in_batch > 0 :
230+ self .stdout .write (
231+ self .style .WARNING (
232+ f" Batch { start + 1 } -{ end } : { successful_in_batch } successful, "
233+ f"{ failed_in_batch } failed (IDs: { failed_records [:5 ]} { '...' if failed_in_batch > 5 else '' } )" ,
234+ ),
235+ )
236+
222237 self .stdout .write (
223238 f" Processed { processed :,} /{ backfill_count :,} records needing backfill "
224239 f"({ processed / backfill_count * 100 :.1f} %)" ,
225240 )
226241
227242 total_processed += processed
228- self .stdout .write (
229- self .style .SUCCESS (
230- f" ✓ Completed { model_name } : { processed :,} records" ,
231- ),
232- )
243+
244+ # Show completion summary
245+ if processed < backfill_count :
246+ self .stdout .write (
247+ self .style .WARNING (
248+ f" ⚠ Completed { model_name } : { processed :,} /{ backfill_count :,} records "
249+ f"({ backfill_count - processed :,} records failed and will need to be retried)" ,
250+ ),
251+ )
252+ else :
253+ self .stdout .write (
254+ self .style .SUCCESS (
255+ f" ✓ Completed { model_name } : { processed :,} records" ,
256+ ),
257+ )
233258
234259 except Exception as e :
235260 self .stdout .write (
236261 self .style .ERROR (f" ✗ Failed to process { model_name } : { e } " ),
237262 )
238263 logger .error (f"Error processing { model_name } : { e } " )
239264
240- if dry_run :
241- self .stdout .write (
242- self .style .SUCCESS (
243- f"\n DRY RUN COMPLETE: Would have processed { total_processed :,} records" ,
244- ),
245- )
246- else :
247- self .stdout .write (
248- self .style .SUCCESS (
249- f"\n BACKFILL COMPLETE: Processed { total_processed :,} records" ,
250- ),
251- )
265+ self .stdout .write (
266+ self .style .SUCCESS (
267+ f"\n BACKFILL COMPLETE: Processed { total_processed :,} records" ,
268+ ),
269+ )
0 commit comments