We use @Scheduled annotation to schedule some tasks. But they are hidden at runtime and can be forgotten easily. It would be very nice to have an overview of all scheduled jobs and their cron values.

If spring-boot-actuator can provide an endpoint listing all scheduled methods we can monitor them via tools like spring-boot-admin (https://github.com/codecentric/spring-boot-admin/issues/432)

Thanks.

Comment From: iNikem

This would be an extremely cool feature. We had in the past problems when some library unexpectedly added Sheduled class and an unwanted job ran in one of our applications. This overview of all jobs would make our troubleshooting much easier :)

Comment From: mballoni

Really cool feature, indeed. Gonna make some tests with custom actuator endpoints as a proof of concept.

Comment From: philwebb

Closing in favor of PR #9623

Comment From: wilkinsona

Here's an example of the response from the new scheduledtasks endpoint:

HTTP/1.1 200 OK
Content-Type: application/vnd.spring-boot.actuator.v2+json;charset=UTF-8
Date: Wed, 15 Nov 2017 10:58:10 GMT
Transfer-Encoding: chunked

{
    "cron": [
        {
            "expression": "0 0 0/6 1/1 * ?",
            "runnable": {
                "target": "com.example.demo.MvcActuatorApplication.someCronTask"
            }
        },
        {
            "expression": "0 0 0/3 1/1 * ?",
            "runnable": {
                "target": "com.example.demo.MvcActuatorApplication$CronTriggeredRunnable"
            }
        }
    ],
    "fixedDelay": [
        {
            "initialDelay": 23,
            "interval": 12,
            "runnable": {
                "target": "com.example.demo.MvcActuatorApplication.someFixedDelayTask"
            }
        },
        {
            "initialDelay": 100,
            "interval": 100,
            "runnable": {
                "target": "com.example.demo.MvcActuatorApplication$FixedDelayRunnable"
            }
        }
    ],
    "fixedRate": [
        {
            "initialDelay": 67,
            "interval": 45,
            "runnable": {
                "target": "com.example.demo.MvcActuatorApplication.someFixedRateTask"
            }
        },
        {
            "initialDelay": 200,
            "interval": 200,
            "runnable": {
                "target": "com.example.demo.MvcActuatorApplication$FixedRateRunnable"
            }
        }
    ]
}

Comment From: selimok

Hey cool, thank you very much for your effort :) It's a great feature.

Comment From: kamaydeo

Does this work with tasks that are scheduled programmatically using TaskScheduler?

Comment From: wilkinsona

@kamaydeo No. You should use ScheduledTaskRegistrar rather than calling TaskScheduler directly.

Comment From: kamaydeo

Thanks. That worked. @Scheduled shows the method name in the /actuator/scheduledtasks. It would be great if ScheduledTaskRegistrar provided a way to specify the name of the scheduled task. When I used lambda with ScheduledTaskRegistrar, /actuator/scheduledtasks shows name of the lambda which is kinda not useful.