Упростил обновление старых пайплайнов

This commit is contained in:
Struchkov Mark 2022-12-20 12:32:27 +03:00
parent cc9e296daf
commit ceaa48487e
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
6 changed files with 25 additions and 29 deletions

View File

@ -19,7 +19,7 @@ public interface PipelineRepository {
Optional<Pipeline> findById(Long pipelineId);
Page<Pipeline> findAllByStatuses(Set<PipelineStatus> statuses, Pageable pagination);
List<Pipeline> findAllByStatuses(Set<PipelineStatus> statuses);
List<Pipeline> findAllById(Set<Long> pipelineIds);

View File

@ -24,7 +24,7 @@ public interface PipelineService {
Pipeline update(@NonNull Pipeline pipeline);
Page<Pipeline> getAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pageable pagination);
List<Pipeline> getAllByStatuses(@NonNull Set<PipelineStatus> statuses);
Page<Pipeline> getAll(@NonNull PipelineFilter filter, @NonNull Pageable pagination);

View File

@ -82,6 +82,8 @@ public class PipelineServiceImpl implements PipelineService {
final Pipeline oldPipeline = repository.findById(pipeline.getId())
.orElseThrow(notFoundException("Pipeline не найден"));
pipeline.setProjectId(pipeline.getProjectId());
if (!oldPipeline.getUpdated().equals(pipeline.getUpdated())) {
notifyNewPipeline(pipeline, oldPipeline.getStatus().name());
return repository.save(pipeline);
@ -98,8 +100,8 @@ public class PipelineServiceImpl implements PipelineService {
}
@Override
public Page<Pipeline> getAllByStatuses(@NonNull Set<PipelineStatus> statuses, @NonNull Pageable pagination) {
return repository.findAllByStatuses(statuses, pagination);
public List<Pipeline> getAllByStatuses(@NonNull Set<PipelineStatus> statuses) {
return repository.findAllByStatuses(statuses);
}
@Override

View File

@ -16,14 +16,13 @@ import dev.struchkov.haiti.utils.network.HttpParse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.convert.ConversionService;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import java.text.MessageFormat;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.ForkJoinTask;
@ -35,7 +34,6 @@ 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.RUNNING;
import static dev.struchkov.bot.gitlab.context.domain.PipelineStatus.WAITING_FOR_RESOURCE;
import static dev.struchkov.haiti.context.exception.ConvertException.convertException;
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.pullTaskResults;
@ -138,27 +136,24 @@ public class PipelineParser {
public void scanOldPipeline() {
log.debug("Старт обработки старых пайплайнов");
int page = 0;
Page<Pipeline> pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PageRequest.of(page, COUNT));
while (pipelineSheet.hasContent()) {
final List<Pipeline> pipelines = pipelineSheet.getContent();
final List<Pipeline> pipelines = pipelineService.getAllByStatuses(oldStatus);
for (Pipeline pipeline : pipelines) {
final Pipeline newPipeline = HttpParse.request(
final Optional<Pipeline> optNewPipeline = HttpParse.request(
MessageFormat.format(gitlabProperty.getUrlPipeline(), pipeline.getProjectId(), pipeline.getId())
)
.header(ACCEPT)
.header(StringUtils.H_PRIVATE_TOKEN, personProperty.getToken())
.execute(PipelineJson.class)
.map(json -> conversionService.convert(json, Pipeline.class))
.orElseThrow(convertException("Ошибка обновления Pipelines"));
.map(json -> conversionService.convert(json, Pipeline.class));
if (optNewPipeline.isPresent()) {
final Pipeline newPipeline = optNewPipeline.get();
pipelineService.update(newPipeline);
} else {
log.error("Ошибка обновления пайплайна. ProjectId:{}, PipelineId:{}", pipeline.getProjectId(), pipeline.getId());
}
}
pipelineSheet = pipelineService.getAllByStatuses(oldStatus, PageRequest.of(++page, COUNT));
}
log.debug("Конец обработки старых пайплайнов");
}

View File

@ -35,8 +35,8 @@ public class PipelineRepositoryImpl implements PipelineRepository {
}
@Override
public Page<Pipeline> findAllByStatuses(Set<PipelineStatus> statuses, Pageable pagination) {
return jpaRepository.findAllByStatusIn(statuses, pagination);
public List<Pipeline> findAllByStatuses(Set<PipelineStatus> statuses) {
return jpaRepository.findAllByStatusIn(statuses);
}
@Override

View File

@ -2,10 +2,9 @@ package dev.struchkov.bot.gitlab.data.jpa;
import dev.struchkov.bot.gitlab.context.domain.PipelineStatus;
import dev.struchkov.bot.gitlab.context.domain.entity.Pipeline;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.support.JpaRepositoryImplementation;
import java.util.List;
import java.util.Set;
/**
@ -13,6 +12,6 @@ import java.util.Set;
*/
public interface PipelineJpaRepository extends JpaRepositoryImplementation<Pipeline, Long> {
Page<Pipeline> findAllByStatusIn(Set<PipelineStatus> statuses, Pageable pageable);
List<Pipeline> findAllByStatusIn(Set<PipelineStatus> statuses);
}