Skip to content

Commit a5b6905

Browse files
committed
enable eta
1 parent 6591e0d commit a5b6905

File tree

1 file changed

+49
-2
lines changed

1 file changed

+49
-2
lines changed

service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,18 @@ class BackfillShowAction @Inject constructor(
178178
)
179179
}
180180
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+
}
183193
}
184194
}
185195
}
@@ -476,6 +486,43 @@ class BackfillShowAction @Inject constructor(
476486
}
477487
}
478488

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+
479526
companion object {
480527
private const val PATH = "/backfills/{id}"
481528
fun path(id: String) = PATH.replace("{id}", id)

0 commit comments

Comments
 (0)