Skip to content

Commit 8c2565a

Browse files
committed
fix configuration variable for local indexing + invoke local + remote indexing
1 parent d29f6ed commit 8c2565a

File tree

6 files changed

+40
-11
lines changed

6 files changed

+40
-11
lines changed

challenges-service.example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"indexing": {
33
"local": {
4-
"paths": "./challenges/local/",
4+
"path": "./challenges/local/",
55
"updateOnChange": true,
66
"updateTimePeriod": null
77
},

src/main/kotlin/org/developerden/codosseum/ChallengesService.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import io.github.oshai.kotlinlogging.KotlinLogging
55
import io.ktor.server.cio.*
66
import kotlinx.coroutines.Dispatchers
77
import kotlinx.coroutines.Job
8+
import org.developerden.codosseum.indexing.Indexed
89
import kotlin.coroutines.CoroutineContext
910

1011
object ChallengesService {
@@ -15,6 +16,7 @@ object ChallengesService {
1516
val coroutineContext: CoroutineContext
1617
get() = Dispatchers.Default + job
1718

19+
val indexed: MutableSet<Indexed> = mutableSetOf()
1820
}
1921

2022
fun main(args: Array<String>) = EngineMain.main(args)

src/main/kotlin/org/developerden/codosseum/ServiceConfiguration.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ data class ServiceConfiguration(
1616

1717
@Serializable
1818
data class Local(
19-
val paths: String,
19+
val path: String,
2020
val updateOnChange: Boolean = true,
2121
val updateTimePeriod: Long? = null
2222
)

src/main/kotlin/org/developerden/codosseum/indexing/Indexing.kt

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.developerden.codosseum.indexing
22

3+
import org.developerden.codosseum.ChallengesService
4+
import org.developerden.codosseum.ServiceConfiguration
5+
import org.developerden.codosseum.indexing.git.RemoteIndexing
36
import java.nio.file.Path
47
import kotlin.io.path.Path
58
import kotlin.io.path.exists
@@ -22,8 +25,21 @@ abstract class Indexing<F> {
2225
}
2326
}
2427

25-
2628
data class Indexed(
2729
val schema: Path? = null,
2830
val challengeDirectory: Path,
29-
)
31+
)
32+
33+
suspend fun indexChallenges(indexing: ServiceConfiguration.Indexing) {
34+
indexing.remote.repositories.map {
35+
ChallengesService.logger.debug { "Indexing repo '${it.name}'..." }
36+
ChallengesService.indexed.addAll(RemoteIndexing.collectIndexedPaths(it))
37+
}
38+
39+
ChallengesService.logger.debug { "Indexing local path '${indexing.local.path}'..." }
40+
val localIndexing = object : Indexing<Path>() {
41+
override suspend fun index(source: Path): Path = source
42+
}
43+
44+
ChallengesService.indexed.addAll(localIndexing.collectIndexedPaths(Path(indexing.local.path)))
45+
}

src/main/kotlin/org/developerden/codosseum/indexing/git/RemoteIndexing.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import kotlin.io.path.createParentDirectories
1010
import kotlin.io.path.notExists
1111
import org.developerden.codosseum.indexing.git.Repository as GitSource
1212

13-
class RemoteIndexing : Indexing<GitSource>() {
13+
object RemoteIndexing : Indexing<GitSource>() {
1414

1515
override suspend fun index(source: GitSource): Path {
1616
val repositoryPath = Path("./challenges/git/${source.name}/")

src/main/kotlin/org/developerden/codosseum/server/Server.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,26 @@ import io.ktor.server.plugins.swagger.*
99
import io.ktor.server.resources.*
1010
import io.ktor.server.routing.*
1111
import io.ktor.server.sse.*
12+
import kotlinx.coroutines.CoroutineScope
13+
import kotlinx.coroutines.async
14+
import kotlinx.coroutines.runBlocking
1215
import kotlinx.serialization.ExperimentalSerializationApi
1316
import kotlinx.serialization.json.Json
1417
import kotlinx.serialization.json.decodeFromStream
1518
import kotlinx.serialization.modules.SerializersModule
1619
import kotlinx.serialization.modules.contextual
1720
import org.developerden.codosseum.ChallengesService
1821
import org.developerden.codosseum.ServiceConfiguration
22+
import org.developerden.codosseum.indexing.indexChallenges
23+
import org.developerden.codosseum.serializers.UUIDSerializer
24+
import org.developerden.codosseum.serializers.ValidationErrorSerializer
1925
import org.developerden.codosseum.server.generated.sandkasten
2026
import org.developerden.codosseum.server.generated.templatespiler
2127
import org.developerden.codosseum.server.koin.FixedKoin
2228
import org.developerden.codosseum.server.routes.challenges.randomChallenge
2329
import org.developerden.codosseum.server.routes.event.EventBus
2430
import org.developerden.codosseum.server.routes.event.events
2531
import org.developerden.codosseum.server.routes.validation.validationSummary
26-
import org.developerden.codosseum.serializers.UUIDSerializer
27-
import org.developerden.codosseum.serializers.ValidationErrorSerializer
2832
import org.developerden.codosseum.validation.SolutionValidationService
2933
import org.koin.core.module.dsl.singleOf
3034
import org.koin.dsl.module
@@ -74,12 +78,19 @@ fun Application.server() {
7478
single { sandkasten(json) }
7579
single { templatespiler(json) }
7680

77-
factory {
78-
json.decodeFromStream<ServiceConfiguration>(
79-
Paths.get(System.getenv()["CONFIGURATION_PATH"] ?: "./challenges-service.json").inputStream()
80-
)
81+
val configuration: ServiceConfiguration = json.decodeFromStream<ServiceConfiguration>(
82+
Paths.get(System.getenv()["CONFIGURATION_PATH"] ?: "./challenges-service.json").inputStream()
83+
)
84+
85+
runBlocking {
86+
CoroutineScope(ChallengesService.coroutineContext).async {
87+
indexChallenges(configuration.indexing)
88+
}.await()
8189
}
8290

91+
92+
single { configuration }
93+
8394
singleOf(::EventBus)
8495
singleOf(::SolutionValidationService)
8596

0 commit comments

Comments
 (0)