@@ -178,8 +178,18 @@ class BackfillShowAction @Inject constructor(
178
178
)
179
179
}
180
180
td(" hidden py-5 pl-8 pr-0 text-right align-top tabular-nums text-gray-700 sm:table-cell" ) { + """ ${partition.matching_records_per_minute} #/m""" }
181
- // TODO properly calculate the ETA until finished
182
- td(" py-5 pl-8 pr-0 text-right align-top tabular-nums text-gray-700" ) { + """ ETA TODO""" }
181
+ td(" py-5 pl-8 pr-0 text-right align-top tabular-nums text-gray-700" ) {
182
+ when {
183
+ ! partition.precomputing_done -> + " Computing size..."
184
+ partition.state != BackfillState .RUNNING -> + " -"
185
+ partition.matching_records_per_minute == null || partition.matching_records_per_minute <= 0 ||
186
+ partition.computed_matching_record_count <= 0 -> + " Calculating..."
187
+ else -> {
188
+ val etaSeconds = (partition.computed_matching_record_count - partition.backfilled_matching_record_count).toDouble() / (partition.matching_records_per_minute / 60.0 )
189
+ + formatEta(etaSeconds * 1000 )
190
+ }
191
+ }
192
+ }
183
193
}
184
194
}
185
195
}
@@ -476,6 +486,43 @@ class BackfillShowAction @Inject constructor(
476
486
}
477
487
}
478
488
489
+ private fun formatEta (etaMillis : Double ): String {
490
+ val durationSeconds = etaMillis / 1000
491
+ var temp = durationSeconds.toLong()
492
+ val sb = StringBuilder ()
493
+
494
+ val years = temp / 31536000
495
+ if (years > 0 ) {
496
+ sb.append(" ${years} y" )
497
+ temp % = 31536000
498
+ }
499
+
500
+ val days = temp / 86400
501
+ if (days > 0 ) {
502
+ sb.append(" ${days} d" )
503
+ temp % = 86400
504
+ }
505
+
506
+ val hours = temp / 3600
507
+ if (hours > 0 ) {
508
+ sb.append(" ${hours} h" )
509
+ temp % = 3600
510
+ }
511
+
512
+ val minutes = temp / 60
513
+ if (minutes > 0 ) {
514
+ sb.append(" ${minutes} m" )
515
+ temp % = 60
516
+ }
517
+
518
+ val seconds = temp
519
+ if (seconds > 0 ) {
520
+ sb.append(" ${seconds} s" )
521
+ }
522
+
523
+ return if (sb.isEmpty()) " < 1s" else sb.toString()
524
+ }
525
+
479
526
companion object {
480
527
private const val PATH = " /backfills/{id}"
481
528
fun path (id : String ) = PATH .replace(" {id}" , id)
0 commit comments