Skip to content

Commit 3bd6c34

Browse files
committed
Use throttle method to manage concurrent
1 parent 434397d commit 3bd6c34

1 file changed

Lines changed: 41 additions & 14 deletions

File tree

jenkins_pipelines/environments/common/pipeline-build-validation.groovy

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def run(params) {
2222
// Declare lock resource use during node bootstrap
2323
mgrCreateBootstrapRepo = 'share resource to avoid running mgr create bootstrap repo in parallel'
2424
retailProxyConfigurationLock = 'lock proxy retail setup'
25+
def muLock = new Object()
26+
def muRunningCount = 0
27+
def muMaxConcurrent = 5
2528
// Variables to store none critical stage run status
2629
def monitoring_stage_result_fail = false
2730
def client_stage_result_fail = false
@@ -587,13 +590,15 @@ def clientTestingStages(params) {
587590
if (params.confirm_before_continue) {
588591
input 'Press any key to start adding Maintenance Update repositories'
589592
}
590-
echo 'Add custom channels and MU repositories'
591-
res_mu_repos = runCucumberRakeTarget("cucumber:build_validation_add_maintenance_update_repositories_${nodeTag}", true, temporaryList)
592-
echoHtmlReportPath("build_validation_add_maintenance_update_repositories_${nodeTag}")
593-
echo "Custom channels and MU repositories status code: ${res_mu_repos}"
594-
if (res_mu_repos != 0) {
595-
required_custom_channel_status[node] = 'FAIL'
596-
error("Add custom channels and MU repositories failed with status code: ${res_mu_repos}")
593+
withThrottle {
594+
echo 'Add custom channels and MU repositories'
595+
res_mu_repos = runCucumberRakeTarget("cucumber:build_validation_add_maintenance_update_repositories_${nodeTag}", true, temporaryList)
596+
echoHtmlReportPath("build_validation_add_maintenance_update_repositories_${nodeTag}")
597+
echo "Custom channels and MU repositories status code: ${res_mu_repos}"
598+
if (res_mu_repos != 0) {
599+
required_custom_channel_status[node] = 'FAIL'
600+
error("Add custom channels and MU repositories failed with status code: ${res_mu_repos}")
601+
}
597602
}
598603
}
599604
}
@@ -611,13 +616,15 @@ def clientTestingStages(params) {
611616
if (params.confirm_before_continue) {
612617
input 'Press any key to start adding common channels'
613618
}
614-
echo 'Add non MU Repositories'
615-
res_non_MU_repositories = runCucumberRakeTarget("cucumber:${build_validation_non_MU_script}", true, temporaryList)
616-
echo "Non MU Repositories status code: ${res_non_MU_repositories}"
617-
echoHtmlReportPath(build_validation_non_MU_script)
618-
if (res_non_MU_repositories != 0) {
619-
required_custom_channel_status[node] = 'FAIL'
620-
error("Add common channels failed with status code: ${res_non_MU_repositories}")
619+
withThrottle {
620+
echo 'Add non MU Repositories'
621+
res_non_MU_repositories = runCucumberRakeTarget("cucumber:${build_validation_non_MU_script}", true, temporaryList)
622+
echo "Non MU Repositories status code: ${res_non_MU_repositories}"
623+
echoHtmlReportPath(build_validation_non_MU_script)
624+
if (res_non_MU_repositories != 0) {
625+
required_custom_channel_status[node] = 'FAIL'
626+
error("Add common channels failed with status code: ${res_non_MU_repositories}")
627+
}
621628
}
622629
}
623630
}
@@ -922,4 +929,24 @@ def echoHtmlReportPath(String rake_target) {
922929
}
923930
}
924931

932+
def withThrottle = { Closure body ->
933+
waitUntil {
934+
def canRun = false
935+
synchronized(muLock) {
936+
if (muRunningCount < muMaxConcurrent) {
937+
muRunningCount++
938+
canRun = true
939+
}
940+
}
941+
return canRun
942+
}
943+
try {
944+
body()
945+
} finally {
946+
synchronized(muLock) {
947+
muRunningCount--
948+
}
949+
}
950+
}
951+
925952
return this

0 commit comments

Comments
 (0)