Hi all, in order to schedule tasks according to certain requirements we have, we're using a custom implementation of the SchedulingConfigurer and setting the list of CronTask we want to execute depending on some configuration values.
This works just fine and the scheduled tasks are being properly executed but, since we're creating the CronTask this way, when we execute the scheduledtasks endpoint we get something, for example, like this:
{
"cron": [{
"runnable": {
"target": "com.example.ScheduledTasksConfiguration$$Lambda$395/212874257"
},
"expression": "0/10 * * * * ?"
}, {
"runnable": {
"target": "com.example.ScheduledTasksConfiguration$$Lambda$396/1881585646"
},
"expression": "0/5 * * * * ?"
} ],
"fixedDelay": [],
"fixedRate": []
}
As you can see, $$Lambda$396/1881585646 is not probably the best way to keep track of the tasks that are being executed, which is our purpose by using actuator. I've been taking a look to the code and this is the part that creates the description:
https://github.com/spring-projects/spring-boot/blob/master/spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/scheduling/ScheduledTasksEndpoint.java#L261
It uses the class name of the runnable used to create the task (a CronTask in our case) to identify the task, so it would be nice if we had another mechanism to set the description. I was thinking probably adding a name property to the base Task class and use it as de descriptor, getting something like this in the endpoint:
{
"cron": [{
"name": "Scheduled Task 1",
"runnable": {
"target": "com.example.ScheduledTasksConfiguration$$Lambda$395/212874257"
},
"expression": "0/10 * * * * ?"
}, {
"name": "Scheduled Task 2",
"runnable": {
"target": "com.example.ScheduledTasksConfiguration$$Lambda$396/1881585646"
},
"expression": "0/5 * * * * ?"
} ],
"fixedDelay": [],
"fixedRate": []
}
Thanks
Comment From: wilkinsona
Thanks for the suggestion. The runnable.target field isn't really intended to be used to identify a task. It's intended to describe, as best we can, the code that'll be run each time the task is invoked. It is unfortunate that the class name of a lambda makes it impossible to identify the actual code, but it's the best that the JDK has to offer at the moment.
As for naming tasks, that's something that'll have to be pursued with the Spring Framework team via a JIRA ticket. If you open an issue with the Framework team, please comment here with a link to it. I'll close this issue for now as, without a Framework change, there's nothing that we can do. If the Framework team accept the suggestion we can re-open this and make use of the new information in the endpoint.
Comment From: william-frank
Up-voting this request. In it's current form the result of this Endpoint in unusable in cases for anything except he @Scheduled annotation, which is used for very basic use-cases only. There is no way easy to override the behavior or the endpoint, this makes Spring Admin Scheduled Tasks page also unusable. Is it possible to at least make the creation of the description configurable, so that it can be customized?
Comment From: snicoll
@william-frank there is no need to "up-vote" a closed issue. The comment above yours makes it clear that there is nothing we can do without a change in Spring Framework. It looks like @jhoanmanuelms didn't follow the suggestion (at least I haven't found an issue) so please go ahead if you want to pursue this.