Skip to content

Commit

Permalink
Implement async processing with delay in opprettArbeidsforhold
Browse files Browse the repository at this point in the history
Added asynchronous handling using `Schedulers.boundedElastic()` to the `opprettArbeidsforhold` method. Introduced a 1-second delay for each status emission to manage downstream processing.
  • Loading branch information
krharum committed Oct 14, 2024
1 parent a43cfd2 commit bae72b1
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
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;
Expand Down Expand Up @@ -53,7 +54,15 @@ public Flux<Arbeidsforhold> getArbeidsforhold(String ident) {
public Flux<HttpStatusCode> opprettArbeidsforhold(KanAnsettesDTO kanAnsettes, String yrke,
String arbeidsforholdstype, Integer stillingsprosent) {

return aaregConsumer.opprettArbeidsforhold(lagArbeidsforhold(kanAnsettes, yrke, arbeidsforholdstype, 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);
}
});
}

/**
Expand Down

0 comments on commit bae72b1

Please sign in to comment.