Skip to content

Commit

Permalink
add ReadinessController
Browse files Browse the repository at this point in the history
  • Loading branch information
hknots committed Dec 16, 2024
1 parent 9aea08d commit 343e195
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions src/main/java/no/fintlabs/provider/ReadinessController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package no.fintlabs.provider;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import no.fintlabs.provider.kafka.offset.OffsetState;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestClientResponseException;

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/ready")
public class ReadinessController {

private final OffsetState offsetState;
private final ProviderClient providerClient;

@GetMapping
public ResponseEntity<Void> readinessCheck() {
try {
return offsetState.equals(providerClient.getExistingOffsetState())
? ResponseEntity.ok().build()
: ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
} catch (RestClientResponseException e) {
log.error("Failed fetching readiness check with status code: {}", e.getStatusCode());
return ResponseEntity.ok().build();
}
}

}

0 comments on commit 343e195

Please sign in to comment.