Skip to content

Commit

Permalink
Merge pull request #61 from Cognifide/await-delay-with-progress
Browse files Browse the repository at this point in the history
Await delay with instance states visible
  • Loading branch information
pun-ky authored Sep 26, 2017
2 parents c07bedf + 4a0acd4 commit a567711
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group 'com.cognifide.gradle'
version '2.0.4'
version '2.0.5'
description = 'Gradle AEM Plugin'
defaultTasks = ['clean', 'publishToMavenLocal']

Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/cognifide/gradle/aem/AemConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import org.gradle.util.ConfigureUtil
import java.io.File
import java.io.Serializable
import java.util.*
import java.util.concurrent.TimeUnit

/**
* Aggregated collection of AEM related configuration.
Expand Down Expand Up @@ -263,14 +264,14 @@ open class AemConfig(project: Project) : Serializable {
* actual operation being performed on AEM like starting JCR package installation or even creating launchpad.
*/
@Input
var awaitDelay: Int = 5000
var awaitDelay: Long = TimeUnit.SECONDS.toMillis(3)

/**
* Time in milliseconds used as interval between next instance stability checks being performed.
* Optimization could be necessary only when instance is heavily loaded.
*/
@Input
var awaitInterval: Int = 1000
var awaitInterval: Long = TimeUnit.SECONDS.toMillis(1)

/**
* After each await interval, instance stability check is being performed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ object InstanceActions {

if (config.awaitDelay > 0) {
logger.info("Delaying due to pending operations on instance(s).")

Behaviors.waitUntil(config.awaitInterval, { timer ->
val instanceStates = instances.map { InstanceState(project, it) }
progressLogger.progress(progressFor(instanceStates, timer))

return@waitUntil (timer.elapsed < config.awaitDelay)
})
}

logger.info("Checking stability of instance(s).")

var lastInstanceStates = -1
Behaviors.waitUntil(config.awaitInterval, { timer ->
val instanceStates = instances.map { InstanceState(project, it) }
Expand All @@ -31,8 +37,7 @@ object InstanceActions {
timer.reset()
}

val instanceProgress = instanceStates.joinToString(" | ") { progressFor(it, timer.ticks, config.awaitTimes) }
progressLogger.progress(instanceProgress)
progressLogger.progress(progressFor(instanceStates, config, timer))

if (config.awaitTimes > 0 && timer.ticks > config.awaitTimes) {
logger.warn("Instance(s) are not stable. Timeout reached after ${Formats.duration(timer.elapsed)}")
Expand All @@ -50,6 +55,12 @@ object InstanceActions {
progressLogger.completed()
}

private fun progressFor(instanceStates: List<InstanceState>, timer: Behaviors.Timer) =
instanceStates.joinToString(" | ") { progressFor(it, timer.ticks, 0) }

private fun progressFor(instanceStates: List<InstanceState>, config: AemConfig, timer: Behaviors.Timer) =
instanceStates.joinToString(" | ") { progressFor(it, timer.ticks, config.awaitTimes) }

private fun progressFor(it: InstanceState, tick: Long, maxTicks: Long): String {
return "${it.instance.name}: ${progressIndicator(it, tick, maxTicks)} ${it.bundleState.statsWithLabels} [${it.bundleState.stablePercent}]"
}
Expand All @@ -61,7 +72,7 @@ object InstanceActions {
" "
}

if (tick.toDouble() / maxTicks.toDouble() > 0.1) {
if (maxTicks > 0 && (tick.toDouble() / maxTicks.toDouble() > 0.1)) {
indicator += " [$tick/$maxTicks tt]"
}

Expand Down

0 comments on commit a567711

Please sign in to comment.