Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce ConcurrentExecutorHelper #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import com.eficode.atlassian.jiraInstanceManager.beans.ProjectBean
import com.eficode.atlassian.jiraInstanceManager.beans.ScriptFieldBean
import com.eficode.atlassian.jiraInstanceManager.beans.SpockResult
import com.eficode.atlassian.jiraInstanceManager.beans.SrJob
import com.eficode.atlassian.jiraInstanceManager.concurrent.ConcurrentExecutorHelper
import groovy.ant.AntBuilder
import groovy.io.FileType
import groovy.json.JsonSlurper
Expand All @@ -35,6 +36,7 @@ import unirest.shaded.org.apache.http.conn.HttpHostConnectException

import java.nio.file.StandardCopyOption


final class JiraInstanceManagerRest {

static Logger log = LoggerFactory.getLogger(JiraInstanceManagerRest.class)
Expand Down Expand Up @@ -1679,19 +1681,16 @@ final class JiraInstanceManagerRest {
}
}

ConcurrentExecutorHelper.executeInParallel({ state ->
directoryFiles.each { subFile ->
String destinationPath = destFilePath + srcFile.relativePath(subFile)

directoryFiles.each { subFile ->

String destinationPath = destFilePath + srcFile.relativePath(subFile)

destinationPath = destinationPath.startsWith("/") ? destinationPath.substring(1) : destinationPath

log.info("\tUpdating:" + subFile.name + ", Destination: " + destinationPath)
assert updateScriptrunnerFile(subFile.text, destinationPath), "Error updating " + subFile.name

}

destinationPath = destinationPath.startsWith("/") ? destinationPath.substring(1) : destinationPath

log.info("\tUpdating:" + subFile.name + ", Destination: " + destinationPath)
state({-> assert updateScriptrunnerFile(subFile.text, destinationPath), "Error updating " + subFile.name})
}
})
} else {
log.info("\tUpdating:" + srcFile.name)
assert updateScriptrunnerFile(srcFile.text, destFilePath), "Error updating " + srcFile.name
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.eficode.atlassian.jiraInstanceManager.concurrent

import java.util.concurrent.*

public class ConcurrentExecutorHelper {

public static <T> List<T> executeInParallel(Closure<List<T>> closure) {
ExecutorService pool = Executors.newFixedThreadPool(10)
ExecutorCompletionService<T> ecs = new ExecutorCompletionService<T>(pool)

List<Future<T>> futures = []
List<T> results = []
try {
closure.call({ task ->
futures << ecs.submit(task)
})
futures.each { future ->
results << future.get()
}
} finally {
pool.shutdown()
}
return results
}


}