This commit is contained in:
EgorAnti
2026-11-18 20:33:27 +03:00
parent 276dbdad8a
commit 77a43fa9cf
114 changed files with 6271 additions and 0 deletions
@@ -0,0 +1,32 @@
package com.example.mtusi_messenger.controller;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import com.example.mtusi_messenger.dto.HealthResponse;
import com.example.mtusi_messenger.exception.ApiExceptions;
import com.example.mtusi_messenger.service.ReadinessService;
@RestController
public class HealthController {
private final ReadinessService readiness;
public HealthController(ReadinessService readiness) {
this.readiness = readiness;
}
@GetMapping("/health/live")
public ResponseEntity<HealthResponse> live() {
return ResponseEntity.ok(new HealthResponse("ok"));
}
@GetMapping("/health/ready")
public ResponseEntity<HealthResponse> ready() {
// Always probe dependencies, even after a failure, so a restored schema
// can move this process back to ACCEPTING_TRAFFIC without a restart.
if (!readiness.probeDependencies() || !readiness.acceptsBusinessTraffic()) {
throw ApiExceptions.unavailable("Application is not accepting traffic");
}
return ResponseEntity.ok(new HealthResponse("ok"));
}
}