From 9c64ed2ebf1d75614a52292ae0eb63e410709242 Mon Sep 17 00:00:00 2001 From: Jeff Hwang Date: Mon, 21 Apr 2025 20:45:40 -0400 Subject: [PATCH 1/2] enable eta --- .../backfila/ui/pages/BackfillShowAction.kt | 51 ++++++++++++++++++- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt index 58de7b222..06a905ae1 100644 --- a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt +++ b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt @@ -178,8 +178,18 @@ class BackfillShowAction @Inject constructor( ) } 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""" } - // TODO properly calculate the ETA until finished - td("py-5 pl-8 pr-0 text-right align-top tabular-nums text-gray-700") { +"""ETA TODO""" } + td("py-5 pl-8 pr-0 text-right align-top tabular-nums text-gray-700") { + when { + partition.state != BackfillState.RUNNING -> +"-" + !partition.precomputing_done -> +"Computing size..." + partition.matching_records_per_minute == null || partition.matching_records_per_minute <= 0 || + partition.computed_matching_record_count <= 0 -> +"Calculating..." + else -> { + val etaSeconds = (partition.computed_matching_record_count - partition.backfilled_matching_record_count).toDouble() / (partition.matching_records_per_minute / 60.0) + +formatEta(etaSeconds * 1000) + } + } + } } } } @@ -476,6 +486,43 @@ class BackfillShowAction @Inject constructor( } } + private fun formatEta(etaMillis: Double): String { + val durationSeconds = etaMillis / 1000 + var temp = durationSeconds.toLong() + val sb = StringBuilder() + + val years = temp / 31536000 + if (years > 0) { + sb.append("${years}y") + temp %= 31536000 + } + + val days = temp / 86400 + if (days > 0) { + sb.append("${days}d") + temp %= 86400 + } + + val hours = temp / 3600 + if (hours > 0) { + sb.append("${hours}h") + temp %= 3600 + } + + val minutes = temp / 60 + if (minutes > 0) { + sb.append("${minutes}m") + temp %= 60 + } + + val seconds = temp + if (seconds > 0) { + sb.append("${seconds}s") + } + + return if (sb.isEmpty()) "< 1s" else sb.toString() + } + companion object { private const val PATH = "/backfills/{id}" fun path(id: String) = PATH.replace("{id}", id) From 3487c725e91138b15db3e6c05e5d62de57b233a2 Mon Sep 17 00:00:00 2001 From: Jeff Hwang Date: Tue, 22 Apr 2025 10:43:29 -0400 Subject: [PATCH 2/2] computing size to computing --- .../kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt index 06a905ae1..a733e8381 100644 --- a/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt +++ b/service/src/main/kotlin/app/cash/backfila/ui/pages/BackfillShowAction.kt @@ -181,7 +181,7 @@ class BackfillShowAction @Inject constructor( td("py-5 pl-8 pr-0 text-right align-top tabular-nums text-gray-700") { when { partition.state != BackfillState.RUNNING -> +"-" - !partition.precomputing_done -> +"Computing size..." + !partition.precomputing_done -> +"Computing..." partition.matching_records_per_minute == null || partition.matching_records_per_minute <= 0 || partition.computed_matching_record_count <= 0 -> +"Calculating..." else -> {