Skip to content

Commit 068a2f8

Browse files
committed
buildSrc: Small improvements
ktor-exposed: Fixed uptime issue
1 parent c40c744 commit 068a2f8

2 files changed

Lines changed: 5 additions & 16 deletions

File tree

buildSrc/src/main/kotlin/SampleProcess.kt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@ import kotlinx.coroutines.withContext
55
import org.gradle.internal.jvm.Jvm
66
import java.io.Closeable
77
import java.io.File
8-
import java.io.IOException
98

109
class SampleProcess(private val output: File, private val description: SampleDescription) : AutoCloseable, Closeable {
1110
private val pid: Long
1211
private val process: Process
13-
private val log by lazy {
12+
init {
1413
output.mkdirs()
15-
File(output, "${description.name}.log").outputStream()
1614
}
15+
private val logFile by lazy { File(output, "${description.name}.log") }
1716

1817
init {
1918
Runtime.getRuntime().exec(arrayOf(Jvm.current().javaExecutable.path, "-jar", description.artifact.path)).also {
@@ -42,12 +41,6 @@ class SampleProcess(private val output: File, private val description: SampleDes
4241
log(line)
4342
}
4443
} while (line != null)
45-
46-
try {
47-
log.flush()
48-
log.close()
49-
} catch (ignore: IOException) {
50-
}
5144
}
5245
}
5346

@@ -56,8 +49,7 @@ class SampleProcess(private val output: File, private val description: SampleDes
5649
}
5750

5851
private fun log(line: String) {
59-
log.write("$line\n".toByteArray())
60-
log.flush()
52+
logFile.appendText("$line\n")
6153
}
6254

6355
val realMemory: Long?

samples/ktor-exposed/src/Application.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ fun main(args: Array<String>) {
3030

3131
@Suppress("unused") // Referenced in application.conf
3232
fun Application.module() {
33-
environment.monitor.subscribe(ApplicationStarted) {
34-
val uptime = ManagementFactory.getRuntimeMXBean().uptime / 1000.0
35-
LoggerFactory.getLogger(Application::class.java).info("Uptime $uptime seconds")
36-
}
37-
3833
install(SqlFeature)
3934
install(ExposedFeature) {
4035
init {
@@ -43,6 +38,8 @@ fun Application.module() {
4338
it.execute("CREATE TABLE persons(id SERIAL, first_name VARCHAR(255), last_name VARCHAR(255))")
4439
}
4540
}
41+
val uptime = ManagementFactory.getRuntimeMXBean().uptime / 1000.0
42+
LoggerFactory.getLogger(Application::class.java).info("Uptime $uptime seconds")
4643
}
4744
}
4845

0 commit comments

Comments
 (0)