Skip to content

Commit

Permalink
Refactor timeout, delay elements, and filtering logic
Browse files Browse the repository at this point in the history
Updated pendingAcquireTimeout to a longer duration, replaced Thread.sleep with delayElements for non-blocking delay, and added a filter to check for a non-null stillingsprosent. These changes improve performance and reliability by optimizing resource acquisition and ensuring valid data processing.
  • Loading branch information
krharum committed Oct 15, 2024
1 parent f00ed2c commit cdfddb2
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public PdlConsumer(
.create(ConnectionProvider.builder("PDL connections")
.maxConnections(1)
.pendingAcquireMaxCount(10000)
.pendingAcquireTimeout(Duration.ofSeconds(30))
.pendingAcquireTimeout(Duration.ofSeconds(3000))
.build())))
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private Flux<KanAnsettesDTO> getPersonSomKanAnsettes(Integer stillingsprosent, D
.flatMap(Flux::fromIterable)
.filter(arbeidsavtale -> nonNull(arbeidsavtale.getBruksperiode()) &&
isNull(arbeidsavtale.getBruksperiode().getTom()))
.filter(arbeidsavtale -> nonNull(arbeidsavtale.getStillingsprosent()))
.map(Arbeidsavtale::getStillingsprosent)
.reduce(0, (a, b) -> (int) (a + b))
.map(sum -> sum + stillingsprosent <= 100)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import org.springframework.http.HttpStatusCode;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.scheduler.Schedulers;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.Duration;
import java.time.LocalDate;
import java.util.List;

Expand Down Expand Up @@ -55,14 +55,7 @@ public Flux<HttpStatusCode> opprettArbeidsforhold(KanAnsettesDTO kanAnsettes, St
String arbeidsforholdstype, Integer stillingsprosent) {

return aaregConsumer.opprettArbeidsforhold(lagArbeidsforhold(kanAnsettes, yrke, arbeidsforholdstype, stillingsprosent))
.publishOn(Schedulers.boundedElastic())
.doOnNext(status -> {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
.delayElements(Duration.ofSeconds(1));
}

/**
Expand Down

0 comments on commit cdfddb2

Please sign in to comment.