1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 16:28:12 -07:00

Minor fixes to the Daniil's timeout checks.

This commit is contained in:
Cedric Beust 2016-01-29 22:59:53 +04:00
parent efd12733ee
commit e441d8bafb
4 changed files with 11 additions and 12 deletions

View file

@ -37,7 +37,7 @@ public class Kobalt {
private val KOBALT_PROPERTIES = "kobalt.properties" private val KOBALT_PROPERTIES = "kobalt.properties"
private val PROPERTY_KOBALT_VERSION = "kobalt.version" private val PROPERTY_KOBALT_VERSION = "kobalt.version"
private val PROPERTY_KOBALT_VERSION_CHECK_TIMEOUT = "kobalt.version.check_timeout" // ISO-8601 private val PROPERTY_KOBALT_VERSION_CHECK_TIMEOUT = "kobalt.version.checkTimeout" // ISO-8601
/** kobalt.properties */ /** kobalt.properties */
private val kobaltProperties: Properties by lazy { readProperties() } private val kobaltProperties: Properties by lazy { readProperties() }
@ -75,7 +75,8 @@ public class Kobalt {
} }
val version = kobaltProperties.getProperty(PROPERTY_KOBALT_VERSION) val version = kobaltProperties.getProperty(PROPERTY_KOBALT_VERSION)
val versionCheckTimeout = Duration.parse(kobaltProperties.getProperty(PROPERTY_KOBALT_VERSION_CHECK_TIMEOUT)) val versionCheckTimeout = Duration.parse(
kobaltProperties.getProperty(PROPERTY_KOBALT_VERSION_CHECK_TIMEOUT) ?: "P1D2H")
fun findPlugin(name: String) = Plugins.findPlugin(name) fun findPlugin(name: String) = Plugins.findPlugin(name)
} }

View file

@ -7,17 +7,16 @@ import java.time.Instant
class VersionCheckTimestampFile { class VersionCheckTimestampFile {
companion object { companion object {
private val KOBALT_VERSION_CHECK_TIMESTAMP_FILE = "versionCheckTimestamp.txt" private val KOBALT_VERSION_CHECK_TIMESTAMP_FILE = "versionCheckTimestamp.txt"
private val checkTimestampFile = File(KFiles.KOBALT_DOT_DIR, KOBALT_VERSION_CHECK_TIMESTAMP_FILE) private val CHECK_TIMESTAMP_FILE = File(KFiles.KOBALT_DOT_DIR, KOBALT_VERSION_CHECK_TIMESTAMP_FILE)
fun updateTimestamp(timestamp: Instant) = KFiles.saveFile(checkTimestampFile, timestamp.toString()) fun updateTimestamp(timestamp: Instant) = KFiles.saveFile(CHECK_TIMESTAMP_FILE, timestamp.toString())
fun getTimestamp(): Instant { val timestamp : Instant
return if(checkTimestampFile.exists()) get() = if (CHECK_TIMESTAMP_FILE.exists()) {
Instant.parse(checkTimestampFile.readText()) Instant.parse(CHECK_TIMESTAMP_FILE.readText())
else { } else {
updateTimestamp(Instant.MIN) updateTimestamp(Instant.MIN)
Instant.MIN Instant.MIN
} }
}
} }
} }

View file

@ -33,9 +33,9 @@ public class UpdateKobalt @Inject constructor(val github: GithubApi, val wrapper
* Accepts Future<String> as `latestVersionFuture` to allow getting `latestVersion` in the background * Accepts Future<String> as `latestVersionFuture` to allow getting `latestVersion` in the background
* */ * */
fun checkForNewVersion(latestVersionFuture: Future<String>) { fun checkForNewVersion(latestVersionFuture: Future<String>) {
if(Kobalt.versionCheckTimeout if (Kobalt.versionCheckTimeout > Duration.between(VersionCheckTimestampFile.timestamp, Instant.now())) {
> Duration.between(VersionCheckTimestampFile.getTimestamp(), Instant.now()))
return // waits `Kobalt.versionCheckTimeout` before the next check return // waits `Kobalt.versionCheckTimeout` before the next check
}
try { try {
val latestVersionString = latestVersionFuture.get() val latestVersionString = latestVersionFuture.get()

View file

@ -1,2 +1 @@
kobalt.version=0.401 kobalt.version=0.401
kobalt.version.check_timeout=P1DT2H