forked from mtusi2026/mtusi2026lab3
init commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package ru.mtusi.messenger.service;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.stereotype.Service;
|
||||
import ru.mtusi.messenger.dto.HealthDTO;
|
||||
import ru.mtusi.messenger.exception.ServiceUnavailableException;
|
||||
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class HealthService {
|
||||
|
||||
private final JdbcTemplate jdbcTemplate;
|
||||
|
||||
public HealthDTO readiness() {
|
||||
try {
|
||||
jdbcTemplate.queryForObject("SELECT 1", Integer.class);
|
||||
} catch (Exception e) {
|
||||
throw new ServiceUnavailableException("Database unavailable");
|
||||
}
|
||||
HealthDTO h = new HealthDTO();
|
||||
h.setStatus(HealthDTO.StatusEnum.OK);
|
||||
return h;
|
||||
}
|
||||
|
||||
public HealthDTO liveness() {
|
||||
HealthDTO h = new HealthDTO();
|
||||
h.setStatus(HealthDTO.StatusEnum.OK);
|
||||
return h;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user