Hi, I have implemented a simple web service and deployed it in Render to test the health check function for the “web service” service. I have a function that returns a response code 500 if the time (minutes) is in a certain time interval, otherwise I return a response code 200. During the specific time my service is not available and it seems that the service is trying to be restarted. Nevertheless, I do not receive an email. Here is my code for the health check endpoint:
Translated with DeepL.com (free version)
// Task Scheduler Bean
@Bean
public ThreadPoolTaskScheduler taskScheduler() {
return new ThreadPoolTaskScheduler();
}
// New Test Controller
@RestController
@RequestMapping("/test")
static class TestController {
@GetMapping
public void testEndpoint(HttpServletResponse response) throws IOException {
LocalTime now = LocalTime.now();
if (now.getMinute() % 10 == 0 || now.getMinute() % 10 < 4){
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Simulated Error");
} else {
response.setStatus(HttpServletResponse.SC_OK);
response.getWriter().write("OK");
}
}
}
}