Failure in scheduled jobs can be tracked only by monitoring the logs as it does not break the application. There can be instances that failure in scheduled jobs can go unnoticed if logs are not monitored actively.
An out of the box feature to send mail notifications on failure of scheduled jobs can be useful. These notifications can be enabled/disabled using application.properties.
This notification framework can be extended to integrate with various platforms like ms-teams, slack using web-hook configurations.
Also this notification framework can be extended to support failure notifications for REST endpoints. There can be multiple HttpStatus
configured programmatically and sending notification on every status except 200
might create unnecessary noise and hence user should be allowed to configure either success status or failure status.
Comment From: wilkinsona
Thank you for the suggestion. There are many ways in which people would want to be notified of failures in scheduled tasks. Email notifications are just one option, and I think it would be too opinionated for Spring Boot to go for that option. This need for flexibility is why Spring Framework's ThreadPoolTaskScheduler
provides a configurable ErrorHandler
strategy that can be used plug in a notification mechanism that meets your specific needs. If the callback doesn't provide you with all of the information that you need to create an appropriate notification, you may want to open a Spring Framework enhancement request.
Also this notification framework can be extended to support failure notifications for REST endpoints. There can be multiple HttpStatus configured programmatically and sending notification on every status except 200 might create unnecessary noise and hence user should be allowed to configure either success status or failure status.
Spring Boot provides integration with Micrometer and will publish metrics about HTTP requests and responses including their status. You can export these metrics to a number of backends where alerts can be configured. You could do something similar with an ErrorHandler
for your scheduled tasks.