Skip to content

Commit

Permalink
Temporarily disable local pruning
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregor Billing committed Feb 18, 2020
1 parent 24e71e5 commit 1189a8c
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ object GoogleServerEnvironmentConfig : ServerEnvironmentConfig {
get() = CONFIG_DATA.getOrNull(1)
?: DEVEL_VERSION

override val usePruning = true

override fun pruningTableExists(tableName: String): Boolean {
val blobId = remotePruningBlob(tableName)
return GCS_SERVICE.get(blobId)?.exists() ?: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ interface ServerEnvironmentConfig {
val projectTitle
get() = "$projectName-$version"

val usePruning: Boolean

fun pruningTableExists(tableName: String): Boolean

fun getPruningTableInput(tableName: String): InputStream
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,7 @@ class WebscramblesServer(val environmentConfig: ServerEnvironmentConfig) : Appli

val wcifHandler = WcifHandler(environmentConfig)

if (environmentConfig.pruningTableExists(THREEPHASE_PRUNING)) {
DataInputStream(environmentConfig.getPruningTableInput(THREEPHASE_PRUNING)).use {
Tools.initFrom(it)
}
} else {
DataOutputStream(environmentConfig.getPruningTableOutput(THREEPHASE_PRUNING)).use {
Tools.saveTo(it)
}
}
initPruning()

app.routing {
PuzzleListHandler.install(this)
Expand All @@ -54,6 +46,20 @@ class WebscramblesServer(val environmentConfig: ServerEnvironmentConfig) : Appli
baseServer.spinUp(app)
}

private fun initPruning() {
if (environmentConfig.usePruning) {
if (environmentConfig.pruningTableExists(THREEPHASE_PRUNING)) {
DataInputStream(environmentConfig.getPruningTableInput(THREEPHASE_PRUNING)).use {
Tools.initFrom(it)
}
} else {
DataOutputStream(environmentConfig.getPruningTableOutput(THREEPHASE_PRUNING)).use {
Tools.saveTo(it)
}
}
}
}

companion object {
const val MIN_HEAP_SIZE_MEGS = 512

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ object LocalServerEnvironmentConfig : ServerEnvironmentConfig {
get() = LocalServerEnvironmentConfig::class.java.getPackage()?.implementationVersion
?: DEVEL_VERSION

override val usePruning: Boolean
get() = System.getenv("CI") != null

private fun getPruningTableCache(assertExists: Boolean = true): File {
val baseDir = File(programDirectory, PRUNING_FOLDER)

Expand Down

0 comments on commit 1189a8c

Please sign in to comment.