diff --git a/server/src/main/kotlin/io/github/jsixface/codexvert/Application.kt b/server/src/main/kotlin/io/github/jsixface/codexvert/Application.kt index 0ca80a4..cb3eb10 100644 --- a/server/src/main/kotlin/io/github/jsixface/codexvert/Application.kt +++ b/server/src/main/kotlin/io/github/jsixface/codexvert/Application.kt @@ -16,6 +16,7 @@ fun Application.module() { migrateDatabases() configureRouting() configureHTTP() + initialize() } diff --git a/server/src/main/kotlin/io/github/jsixface/codexvert/Initializer.kt b/server/src/main/kotlin/io/github/jsixface/codexvert/Initializer.kt new file mode 100644 index 0000000..74cab5c --- /dev/null +++ b/server/src/main/kotlin/io/github/jsixface/codexvert/Initializer.kt @@ -0,0 +1,18 @@ +package io.github.jsixface.codexvert + +import io.github.jsixface.codexvert.api.VideoApi +import io.ktor.server.application.Application +import io.ktor.server.application.log +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import org.koin.ktor.ext.inject + +fun Application.initialize() { + val videoApi by inject() + log.info("initialize application...") + + CoroutineScope(Dispatchers.IO).launch { + videoApi.updateCache() + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/io/github/jsixface/codexvert/api/VideoApi.kt b/server/src/main/kotlin/io/github/jsixface/codexvert/api/VideoApi.kt index e318114..2ab53b8 100644 --- a/server/src/main/kotlin/io/github/jsixface/codexvert/api/VideoApi.kt +++ b/server/src/main/kotlin/io/github/jsixface/codexvert/api/VideoApi.kt @@ -15,7 +15,7 @@ class VideoApi(private val parser: IParser, private val repo: IVideoFilesRepo) { private val logger = logger() private var cache = emptyList() - private suspend fun updateCache() { + suspend fun updateCache() { logger.info("${this::class.simpleName} updateCache()") cache = repo.getAll().map { it.toVideoFile() } }