Monitor Spring Boot @Scheduled Tasks with CronRabbit

Java

The Problem

Spring Boot @Scheduled tasks run inside the application JVM. If the app runs out of memory, the scheduler thread hangs, or an exception goes unhandled, tasks stop silently.

The Solution

Add a RestTemplate or WebClient call to CronRabbit inside your @Scheduled method to verify execution.

Pattern

Inject a RestTemplate bean and add ping calls to your scheduled methods. Use @Async if the ping shouldn't block the task completion.

Code Examples

Spring Boot @Scheduled with monitoring

Java
@Component
public class ScheduledTasks {
    private final RestTemplate rest = new RestTemplate();
    private static final String PING = "https://ping.cronrabbit.com/your-id";

    @Scheduled(cron = "0 0 2 * * *")
    public void nightlyCleanup() {
        rest.getForObject(PING + "/start", String.class);
        try {
            cleanExpiredSessions();
            archiveOldRecords();
            rest.getForObject(PING, String.class);
        } catch (Exception e) {
            rest.getForObject(PING + "/fail", String.class);
            throw e;
        }
    }
}

Ready to Monitor Your Cron Jobs?

Create your free account and add your first monitor in under 5 minutes. No credit card required.