Skip to content

Commit

Permalink
use thread pool to fetch branch commit
Browse files Browse the repository at this point in the history
  • Loading branch information
xloypaypa authored and kevinlzw committed Dec 29, 2022
1 parent 548b8ad commit fa53948
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,18 @@ import java.time.Instant
import java.time.ZoneOffset
import java.time.ZonedDateTime
import java.time.temporal.ChronoUnit
import java.util.concurrent.Executors
import java.util.concurrent.FutureTask
import java.util.concurrent.atomic.AtomicInteger

@Service("githubActionsPipelineCommitsService")
class PipelineCommitService(
private val buildRepository: BuildRepository,
private val commitService: CommitService
) {
private val defaultNumberOfBranchFetchConcurrency = 10
private val executorService = Executors.newFixedThreadPool(defaultNumberOfBranchFetchConcurrency)

fun mapCommitToRun(
pipeline: PipelineConfiguration,
runs: MutableList<GithubActionsRun>,
Expand All @@ -28,8 +33,9 @@ class PipelineCommitService(
val numberOfBranches = runsGroupedByBranch.size
val progressCounter = AtomicInteger(0)

runsGroupedByBranch
.forEach { (branch, run) ->
val taskMap: MutableMap<String, FutureTask<Map<GithubActionsRun, List<Commit>>>> = mutableMapOf()
runsGroupedByBranch.forEach { (branch, run) ->
val branchTask = FutureTask {
emitCb(
SyncProgress(
pipeline.id,
Expand All @@ -40,8 +46,15 @@ class PipelineCommitService(
GithubActionConstants.totalNumberOfSteps,
)
)
branchCommitsMap[branch] = mapRunToCommits(pipeline, run)
mapRunToCommits(pipeline, run)
}
taskMap[branch] = branchTask
executorService.submit(branchTask)
}
runsGroupedByBranch.forEach { (branch, _) ->
branchCommitsMap[branch] = taskMap[branch]!!.get()
}

return branchCommitsMap.toMap()
}

Expand Down

0 comments on commit fa53948

Please sign in to comment.