Spring-boot: Overview of @Scheduled methods (spring-boot-actuator)

Created on 6 Apr 2017  路  8Comments  路  Source: spring-projects/spring-boot

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.

superseded enhancement

Most helpful comment

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"
            }
        }
    ]
}

All 8 comments

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 :)

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

Closing in favor of PR #9623

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"
            }
        }
    ]
}

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

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

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

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.

Was this page helpful?
0 / 5 - 0 ratings