Skip to content

Commit 622384f

Browse files
Instance stability checking impr (#941)
* Instance stability checking impr * Done times * Detekt fix
1 parent 90bcd00 commit 622384f

File tree

7 files changed

+54
-18
lines changed

7 files changed

+54
-18
lines changed

src/main/kotlin/com/cognifide/gradle/aem/common/instance/action/AwaitDownAction.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,13 @@ class AwaitDownAction(aem: AemExtension) : DefaultAction(aem) {
5454

5555
private val runner = CheckRunner(aem).apply {
5656
delay.apply {
57-
convention(TimeUnit.SECONDS.toMillis(1))
57+
convention(TimeUnit.SECONDS.toMillis(3))
5858
aem.prop.long("instance.awaitDown.delay")?.let { set(it) }
5959
}
60+
doneTimes.apply {
61+
convention(3)
62+
aem.prop.long("instance.awaitDown.doneTimes")?.let { set(it) }
63+
}
6064
verbose.apply {
6165
convention(true)
6266
aem.prop.boolean("instance.awaitDown.verbose")?.let { set(it) }

src/main/kotlin/com/cognifide/gradle/aem/common/instance/action/AwaitUpAction.kt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,19 @@ class AwaitUpAction(aem: AemExtension) : DefaultAction(aem) {
121121
unchangedOptions = options
122122
}
123123

124+
fun runner(options: CheckRunner.() -> Unit) {
125+
runner.apply(options)
126+
}
127+
124128
private val runner = CheckRunner(aem).apply {
125129
delay.apply {
126-
convention(TimeUnit.SECONDS.toMillis(1))
130+
convention(TimeUnit.SECONDS.toMillis(3))
127131
aem.prop.long("instance.awaitUp.delay")?.let { set(it) }
128132
}
133+
doneTimes.apply {
134+
convention(5)
135+
aem.prop.long("instance.awaitUp.doneTimes")?.let { set(it) }
136+
}
129137
verbose.apply {
130138
aem.prop.boolean("instance.awaitUp.verbose")?.let { set(it) }
131139
}
@@ -156,4 +164,11 @@ class AwaitUpAction(aem: AemExtension) : DefaultAction(aem) {
156164

157165
runner.check(instances)
158166
}
167+
168+
companion object {
169+
fun quickOptions(): AwaitUpAction.() -> Unit = {
170+
runner { doneTimes.set(1) }
171+
unchanged { enabled.set(false) }
172+
}
173+
}
159174
}

src/main/kotlin/com/cognifide/gradle/aem/common/instance/check/CheckRunner.kt

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.apache.commons.lang3.time.StopWatch
1010
import java.util.concurrent.Callable
1111
import java.util.concurrent.Executors
1212
import java.util.concurrent.TimeUnit
13+
import java.util.concurrent.TimeoutException
1314

1415
class CheckRunner(internal val aem: AemExtension) {
1516

@@ -37,7 +38,7 @@ class CheckRunner(internal val aem: AemExtension) {
3738
}
3839

3940
/**
40-
* How long to wait after failed checking before checking again.
41+
* How long to wait before checking instances again.
4142
*/
4243
val delay = aem.obj.long { convention(0L) }
4344

@@ -46,6 +47,11 @@ class CheckRunner(internal val aem: AemExtension) {
4647
*/
4748
val timeout = aem.obj.long { convention(10_000L) }
4849

50+
/**
51+
* How many times repeat checking to be sure if the done state is not only temporary.
52+
*/
53+
val doneTimes = aem.obj.long { convention(1) }
54+
4955
/**
5056
* Controls if aborted running should fail build.
5157
*/
@@ -82,7 +88,7 @@ class CheckRunner(internal val aem: AemExtension) {
8288
}
8389
}
8490

85-
@Suppress("LoopWithTooManyJumpStatements", "TooGenericExceptionCaught")
91+
@Suppress("LoopWithTooManyJumpStatements", "TooGenericExceptionCaught", "LongMethod")
8692
private fun ProgressIndicator.doChecking(instances: Collection<Instance>) {
8793
step = "Checking"
8894

@@ -105,24 +111,40 @@ class CheckRunner(internal val aem: AemExtension) {
105111

106112
logger.info("Checking started for $instance")
107113

114+
var doneTime = 0L
108115
do {
109116
if (aborted) {
110117
logger.info("Checking aborted for $instance!")
111118
break
112119
}
113-
114120
val checks = try {
115121
val future = executors.submit(Callable { doChecking(progress) })
116122
future.get(timeout.get(), TimeUnit.MILLISECONDS)
123+
} catch (e: TimeoutException) {
124+
doneTime = 0
125+
logger.info("Checking timed out for $instance")
126+
null
117127
} catch (e: Exception) {
128+
doneTime = 0
118129
logger.error("Checking failed for $instance!", e)
119130
null
120131
}
121-
if (checks != null && checks.done) {
122-
logger.info("Checking done for $instance")
123-
break
132+
if (checks != null) {
133+
if (checks.done) {
134+
if (doneTimes.get() <= 1) {
135+
logger.info("Checking done for $instance")
136+
break
137+
} else {
138+
doneTime++
139+
logger.info("Checking done ($doneTime/${doneTimes.get()}) for $instance")
140+
if (doneTime == doneTimes.get()) {
141+
break
142+
}
143+
}
144+
} else {
145+
doneTime = 0
146+
}
124147
}
125-
126148
Behaviors.waitFor(delay.get())
127149
} while (isActive)
128150

src/main/kotlin/com/cognifide/gradle/aem/common/instance/provision/Provisioner.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ class Provisioner(val manager: InstanceManager) {
6969
private val steps = mutableListOf<Step>()
7070

7171
private var awaitUpOptions: AwaitUpAction.() -> Unit = {
72+
runner { doneTimes.set(1) }
7273
unchanged { enabled.set(false) }
7374
}
7475

src/main/kotlin/com/cognifide/gradle/aem/instance/tasks/InstanceDeploy.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ open class InstanceDeploy : Instance() {
3131
}
3232
}
3333

34-
private var awaitUpOptions: AwaitUpAction.() -> Unit = {
35-
unchanged { enabled.set(false) }
36-
}
34+
private var awaitUpOptions: AwaitUpAction.() -> Unit = {}
3735

3836
fun awaitUp(options: AwaitUpAction.() -> Unit) {
3937
this.awaitUpOptions = options

src/main/kotlin/com/cognifide/gradle/aem/instance/tasks/InstanceProvision.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ open class InstanceProvision : Instance() {
1717
}
1818
}
1919

20-
private var awaitUpOptions: AwaitUpAction.() -> Unit = {
21-
unchanged { enabled.set(false) }
22-
}
20+
private var awaitUpOptions = AwaitUpAction.quickOptions()
2321

2422
fun awaitUp(options: AwaitUpAction.() -> Unit) {
2523
this.awaitUpOptions = options

src/main/kotlin/com/cognifide/gradle/aem/instance/tasks/InstanceUp.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ import org.gradle.api.tasks.TaskAction
88

99
open class InstanceUp : LocalInstance() {
1010

11-
private var awaitOptions: AwaitUpAction.() -> Unit = {
12-
unchanged { enabled.set(false) }
13-
}
11+
private var awaitOptions = AwaitUpAction.quickOptions()
1412

1513
/**
1614
* Controls instance awaiting.

0 commit comments

Comments
 (0)