Рефакторинг PipelineParser
This commit is contained in:
parent
e02187d9c1
commit
18672cf341
@ -34,6 +34,7 @@ import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.PENDING;
|
|||||||
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.PREPARING;
|
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.PREPARING;
|
||||||
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.RUNNING;
|
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.RUNNING;
|
||||||
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.WAITING_FOR_RESOURCE;
|
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.WAITING_FOR_RESOURCE;
|
||||||
|
import static dev.struchkov.haiti.utils.Checker.checkFalse;
|
||||||
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
|
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
|
||||||
import static dev.struchkov.haiti.utils.concurrent.ForkJoinUtils.pullTaskResult;
|
import static dev.struchkov.haiti.utils.concurrent.ForkJoinUtils.pullTaskResult;
|
||||||
import static dev.struchkov.haiti.utils.concurrent.ForkJoinUtils.pullTaskResults;
|
import static dev.struchkov.haiti.utils.concurrent.ForkJoinUtils.pullTaskResults;
|
||||||
@ -84,23 +85,14 @@ public class PipelineParser {
|
|||||||
final Map<Long, Long> pipelineProjectMap = getPipelineShortJsons(projectIds).stream()
|
final Map<Long, Long> pipelineProjectMap = getPipelineShortJsons(projectIds).stream()
|
||||||
.collect(Collectors.toMap(PipelineShortJson::getId, PipelineShortJson::getProjectId));
|
.collect(Collectors.toMap(PipelineShortJson::getId, PipelineShortJson::getProjectId));
|
||||||
|
|
||||||
if (!pipelineProjectMap.isEmpty()) {
|
if (checkNotEmpty(pipelineProjectMap)) {
|
||||||
final ExistContainer<Pipeline, Long> existContainer = pipelineService.existsById(pipelineProjectMap.keySet());
|
final ExistContainer<Pipeline, Long> existContainer = pipelineService.existsById(pipelineProjectMap.keySet());
|
||||||
|
|
||||||
if (!existContainer.isAllFound()) {
|
if (checkFalse(existContainer.isAllFound())) {
|
||||||
final Set<Long> idsNotFound = existContainer.getIdNoFound();
|
final Set<Long> idsNotFound = existContainer.getIdNoFound();
|
||||||
|
|
||||||
final List<ForkJoinTask<PipelineJson>> tasks = idsNotFound.stream()
|
final List<PipelineJson> pipelineJsons = getNewPipelineJson(pipelineProjectMap, idsNotFound);
|
||||||
.map(pipelineId -> new GetPipelineTask(
|
|
||||||
gitlabProperty.getUrlPipeline(),
|
|
||||||
pipelineProjectMap.get(pipelineId),
|
|
||||||
pipelineId,
|
|
||||||
personProperty.getToken()
|
|
||||||
))
|
|
||||||
.map(forkJoinPool::submit)
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
final List<PipelineJson> pipelineJsons = pullTaskResult(tasks);
|
|
||||||
if (checkNotEmpty(pipelineJsons)) {
|
if (checkNotEmpty(pipelineJsons)) {
|
||||||
final List<Pipeline> newPipelines = pipelineJsons.stream()
|
final List<Pipeline> newPipelines = pipelineJsons.stream()
|
||||||
.map(json -> conversionService.convert(json, Pipeline.class))
|
.map(json -> conversionService.convert(json, Pipeline.class))
|
||||||
@ -114,6 +106,21 @@ public class PipelineParser {
|
|||||||
log.debug("Конец обработки новых пайплайнов");
|
log.debug("Конец обработки новых пайплайнов");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<PipelineJson> getNewPipelineJson(Map<Long, Long> pipelineProjectMap, Set<Long> idsNotFound) {
|
||||||
|
final List<ForkJoinTask<PipelineJson>> tasks = idsNotFound.stream()
|
||||||
|
.map(pipelineId -> new GetPipelineTask(
|
||||||
|
gitlabProperty.getUrlPipeline(),
|
||||||
|
pipelineProjectMap.get(pipelineId),
|
||||||
|
pipelineId,
|
||||||
|
personProperty.getToken()
|
||||||
|
))
|
||||||
|
.map(forkJoinPool::submit)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
final List<PipelineJson> pipelineJsons = pullTaskResult(tasks);
|
||||||
|
return pipelineJsons;
|
||||||
|
}
|
||||||
|
|
||||||
private List<PipelineShortJson> getPipelineShortJsons(Set<Long> projectIds) {
|
private List<PipelineShortJson> getPipelineShortJsons(Set<Long> projectIds) {
|
||||||
LocalDateTime newLastUpdate = LocalDateTime.now();
|
LocalDateTime newLastUpdate = LocalDateTime.now();
|
||||||
final List<ForkJoinTask<List<PipelineShortJson>>> tasks = projectIds.stream()
|
final List<ForkJoinTask<List<PipelineShortJson>>> tasks = projectIds.stream()
|
||||||
|
Loading…
Reference in New Issue
Block a user