You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.2 KiB

package alfred.running
import alfred.BuildId
import io.quarkus.runtime.annotations.RegisterForReflection
import io.quarkus.scheduler.Scheduled
import java.time.Instant
import javax.enterprise.context.ApplicationScoped
@ApplicationScoped
class Handles {
private val handles = mutableListOf<Handle>()
fun add(handle: Handle) =
handles.add(handle)
fun active(buildId: BuildId) =
handles
.filter { it.buildId == buildId }
.map {
HandleInfo(
command = it.command,
startedAt = it.startedAt,
user = it.user,
alive = it.handle.isAlive
)
}
@Scheduled(every = "60s")
fun cleanup() {
handles.removeIf { !it.handle.isAlive }
}
}
data class Handle(
val handle: ProcessHandle,
val buildId: BuildId
) {
val command: String = handle.info().commandLine().orElse("")
val startedAt: Instant? = handle.info().startInstant().orElse(null)
val user: String? = handle.info().user().orElse(null)
}
@RegisterForReflection
data class HandleInfo(
val command: String,
val startedAt: Instant?,
val alive: Boolean,
val user: String?
)