-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
34 additions
and
0 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/main/java/no/fintlabs/provider/ReadinessController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
|
||
} |