Skip to content

Commit

Permalink
Refactor AnsettelseService to remove manual threading. #deploy-levend…
Browse files Browse the repository at this point in the history
…e-arbeidsforhold-ansettelse

Removed the explicit use of Threads and handling interruptions. Streamlined the service execution and added error logging for better maintainability and debugging.
  • Loading branch information
krharum committed Oct 15, 2024
1 parent 809da7e commit 527e6ce
Showing 1 changed file with 2 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,23 +45,9 @@ public class AnsettelseService {
private final AnsettelseLoggService ansettelseLoggService;

@Async
@Transactional
public void runAnsettelseService() {

Thread thread = new Thread(this::ansettelseService);
thread.start();
try {
thread.join(3_500_000); //Timeout etter 3000 sekunder
if (thread.isAlive()) {
thread.interrupt();
log.info("Timeout occurred");
}
} catch (InterruptedException e) {
log.info("Timet ut");
}
}

@Transactional
public void ansettelseService() {

var startTime = System.currentTimeMillis();

Expand All @@ -84,6 +70,7 @@ public void ansettelseService() {
.flatMap(count -> tenorConsumer.hentOrganisasjon())
.flatMap(organisasjon -> sjekkOgSendinnArbeidsforhold(organisasjon, parametere, yrkeskoder, datoIntervaller))
.collectList()
.doOnError(e -> log.error("AnsettelseService feilet", e))
.subscribe(status -> log.info("Oppretting ferdig, antall ansettelser {}, medgått tid {} sekunder", status.size(),
(System.currentTimeMillis() - startTime) / 1000));
}
Expand Down

0 comments on commit 527e6ce

Please sign in to comment.