Skip to content

Commit

Permalink
Show running backfills for user
Browse files Browse the repository at this point in the history
  • Loading branch information
adrw committed Jan 9, 2025
1 parent e29a5b0 commit 726af0c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ interface BackfillRunQuery : Query<DbBackfillRun> {
@Constraint("state", Operator.NE)
fun stateNot(state: BackfillState): BackfillRunQuery

@Constraint("created_by_user", Operator.EQ)
fun createdByUser(user: String): BackfillRunQuery

@Order("id", asc = false)
fun orderByIdDesc(): BackfillRunQuery

@Order("updated_at", asc = false)
fun orderByUpdatedAtDesc(): BackfillRunQuery
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
package app.cash.backfila.ui.components

import app.cash.backfila.dashboard.GetBackfillRunsAction
import app.cash.backfila.service.persistence.BackfilaDb
import app.cash.backfila.service.persistence.BackfillRunQuery
import app.cash.backfila.service.persistence.BackfillState
import jakarta.inject.Inject
import kotlinx.html.TagConsumer
import kotlinx.html.div
import kotlinx.html.main
import kotlinx.html.script
import misk.MiskCaller
import misk.config.AppName
import misk.hibernate.Query
import misk.hibernate.Transacter
import misk.hibernate.newQuery
import misk.hotwire.buildHtml
import misk.scope.ActionScoped
import misk.tailwind.Link
Expand All @@ -34,6 +40,8 @@ class DashboardPageLayout @Inject constructor(
private val deployment: Deployment,
private val clientHttpCall: ActionScoped<HttpCall>,
private val getBackfillRunsAction: GetBackfillRunsAction,
@BackfilaDb private val transacter: Transacter,
private val queryFactory: Query.Factory,
) {
private var newBuilder = false
private var headBlock: TagConsumer<*>.() -> Unit = {}
Expand All @@ -60,6 +68,8 @@ class DashboardPageLayout @Inject constructor(
deployment = deployment,
clientHttpCall = clientHttpCall,
getBackfillRunsAction = getBackfillRunsAction,
transacter = transacter,
queryFactory = queryFactory,
).setNewBuilder()

fun title(title: String) = apply {
Expand Down Expand Up @@ -135,50 +145,53 @@ class DashboardPageLayout @Inject constructor(
private fun buildMenuSections(
currentPath: String,
): List<MenuSection> {
val callerBackfills = getBackfillRunsAction.backfillRuns(serviceName, variant)
return transacter.transaction { session ->
val runningBackfills = queryFactory.newQuery<BackfillRunQuery>()
.createdByUser(callerProvider.get()!!.user!!)
.state(BackfillState.RUNNING)
.orderByUpdatedAtDesc()
.list(session)

return listOf(
MenuSection(
title = "Backfila",
links = listOf(
Link(
label = "Services",
href = "/services/",
isSelected = currentPath.startsWith("/services/"),
),
Link(
label = "Backfills",
href = "/backfills/",
isSelected = currentPath.startsWith("/backfills/"),
// TODO get services from REgistry for user || group backfills by service

listOf(
MenuSection(
title = "Backfila",
links = listOf(
Link(
label = "Services",
href = "/services/",
isSelected = currentPath.startsWith("/services/"),
),
Link(
label = "Backfills",
href = "/backfills/",
isSelected = currentPath.startsWith("/backfills/"),
),
),
),
),
MenuSection(
title = "Your Services",
links = listOf(
Link(
label = "Fine Dining",
href = "/services/?q=FineDining",
isSelected = currentPath.startsWith("/services/?q=FindDining"),
MenuSection(
title = "Your Services",
links = listOf(
Link(
label = "Fine Dining",
href = "/services/?q=FineDining",
isSelected = currentPath.startsWith("/services/?q=FindDining"),
),
),
),
),
MenuSection(
title = "Your Backfills",
links = listOf(
Link(
label = "FineDining #0034",
href = "/services/",
isSelected = currentPath.startsWith("/backfill/"),
),
Link(
label = "FineDining #0067",
href = "/backfill/",
isSelected = currentPath.startsWith("/backfill/"),
),
MenuSection(
title = "Your Backfills",
links = runningBackfills.map { backfill ->
Link(
label = backfill.service.registry_name + " #" + backfill.id,
href = "/backfills/${backfill.id}",
isSelected = currentPath.startsWith("/backfills/${backfill.id}"),
)
},
),
),
)
)
}
}

companion object {
Expand Down

0 comments on commit 726af0c

Please sign in to comment.