Skip to content

Commit 1fd1b06

Browse files
author
Derek Smart
committed
limit retries based on param
Signed-off-by: Derek Smart <derek.smart@delphix.com>
1 parent 627aba0 commit 1fd1b06

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

src/main/kotlin/com/delphix/yamlparser/Parser.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package com.delphix.yamlparser
22

33
import com.github.ajalt.clikt.core.CliktCommand
44
import com.github.ajalt.clikt.parameters.options.*
5+
import com.github.ajalt.clikt.parameters.types.int
6+
57
import io.github.cdimascio.dotenv.dotenv as Dotenv
68

79
import com.delphix.yamlparser.sdk.Delphix as Delphix
@@ -73,6 +75,8 @@ object Parser {
7375
class Parse : CliktCommand() {
7476
val env: String by option(help="Path to env file.").default(".env")
7577
val bookmark: String by option(help="Bookmark name.").default("")
78+
val retryLimit: Int by option(help="Number of times to wait for a busy job.").int().default(5)
79+
val waitTime: Int by option(help="Seconds to wait for a busy job before retrying.").int().default(30)
7680

7781
override fun run(){
7882
val file = File("delphix.yaml")
@@ -94,7 +98,7 @@ object Parser {
9498
val env: Map<String, String> = loadEnvs(env)
9599
val delphix: Delphix = Delphix(Http(env["delphixEngine"]?: ""))
96100
val yaml: Yaml = Mapper().mapYaml(contents)
97-
val runner: Runner = Runner(yaml, env, delphix, bookmark)
101+
val runner: Runner = Runner(yaml, env, delphix, bookmark, retryLimit, waitTime)
98102

99103
try {
100104
runner.run()

src/main/kotlin/com/delphix/yamlparser/Runner.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ class Runner (
99
val yaml: Yaml,
1010
val env: Map<String, String>,
1111
val delphix: Delphix,
12-
val bookmark: String
12+
val bookmark: String,
13+
val retryLimit: Int,
14+
val waitTime: Int
1315
) {
1416
var currentAction: JSONObject = JSONObject()
1517

@@ -63,11 +65,18 @@ class Runner (
6365
}
6466

6567
fun execActionPhase(environment: Environment) {
66-
for (action in environment.actions) {
68+
loop@ for (action in environment.actions) {
6769
if (action.event == env["gitEvent"]) {
70+
var tries = 1
6871
while(jobConflictExists(environment.datapod)) {
69-
println("Job Conflict Exists. Waiting 30 seconds to try again.")
70-
Thread.sleep(30000)
72+
if (tries > retryLimit) {
73+
println("Retry Limit Exceeded for Job Conflict.")
74+
break@loop
75+
}
76+
println("Job Conflict Exists. Waiting $waitTime seconds to try again.")
77+
val waitMil = waitTime * 1000
78+
Thread.sleep(waitMil.toLong())
79+
tries++
7180
}
7281
callDelphix(environment.datapod, environment.name, action.action)
7382
outputStatus(environment.name, action.event, action.action)

src/test/kotlin/com/delphix/yamlparser/RunnerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class RunnerTest {
2424
val yaml: Yaml = Mapper().mapYaml(mapJsonToNode(jsonString))
2525
val env: Map<String, String> = mapOf("gitBranch" to "origin/develop", "gitCommit" to "0bb822091eed2ae15d67ed91f3ba8591b39e6c4e", "gitEvent" to "push", "delphixEngine" to "delphixEngine", "delphixUser" to "delphixUser", "delphixPass" to "delphixPass", "delphixRepository" to "Postgres vFiles (9.6.8)")
2626
val delphix : Delphix = mock()
27-
val runner: Runner = Runner(yaml, env, delphix, "bookmark")
27+
val runner: Runner = Runner(yaml, env, delphix, "bookmark", 5, 30)
2828

2929
@Test fun `can call Delphix`() : Unit {
3030
/*

0 commit comments

Comments
 (0)