-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Rewrite GithubDownload to use ktor and ktx.serialization instead of curl, jq, and grep - Handle printing http errors from GitHub better - Remove dependency on JsonPath, instead use ktx.serialization to read the json object - Format info messages to be more gay - Add done in x seconds at the end - Stop SLF4J info message from printing
- Loading branch information
Showing
9 changed files
with
127 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
kotlin.code.style=official | ||
version=2.0.0-beta.2 | ||
version=2.0.0-beta.3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 11 additions & 14 deletions
25
src/main/kotlin/commands/CachedCommand.kt → src/main/kotlin/helpers/CachedRequest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,37 @@ | ||
package commands | ||
package helpers | ||
|
||
import evalBash | ||
import java.nio.file.Path | ||
import java.time.LocalDateTime | ||
import kotlin.io.path.* | ||
import kotlin.time.Duration | ||
import kotlin.time.toJavaDuration | ||
|
||
class CachedCommand(val command: String, val path: Path, val expiration: Duration? = null) { | ||
class Result( | ||
class CachedRequest(val path: Path, val expiration: Duration? = null, val evaluate: suspend () -> Result<String>) { | ||
class Returned( | ||
val wasCached: Boolean, | ||
val result: String, | ||
) | ||
|
||
fun getFromCacheOrEval(): Result { | ||
suspend fun getFromCacheOrEval(): Result<Returned> { | ||
val expirationPath = path.parent / (path.name + ".expiration") | ||
// get current time | ||
val time = LocalDateTime.now() | ||
val expiryDate = expirationPath.takeIf { it.exists() }?.readText()?.let { LocalDateTime.parse(it) } | ||
|
||
if (path.exists() && (expiryDate == null || time < expiryDate)) { | ||
return Result(true, path.readText()) | ||
return Result.success(Returned(true, path.readText())) | ||
} | ||
|
||
val evaluated = command.evalBash(env = mapOf()) | ||
.onFailure { | ||
throw IllegalStateException("Failed to evaluate command $command, result:\n${this.stderr.joinToString("\n")}") | ||
} | ||
.getOrThrow() | ||
path.deleteIfExists() | ||
path.createParentDirectories().createFile().writeText(evaluated) | ||
val evaluated = evaluate() | ||
evaluated.onSuccess { | ||
path.deleteIfExists() | ||
path.createParentDirectories().createFile().writeText(it) | ||
} | ||
// write expiration date | ||
if (expiration != null) { | ||
expirationPath.deleteIfExists() | ||
expirationPath.createFile().writeText((time + expiration.toJavaDuration()).toString()) | ||
} | ||
return Result(false, evaluated) | ||
return evaluated.map { Returned(false, it) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters