Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide read access to the scheduled tasks at runtime [SPR-15982] #20532

Closed
spring-issuemaster opened this issue Sep 20, 2017 · 7 comments
Closed
Assignees
Milestone

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Sep 20, 2017

Andy Wilkinson opened SPR-15982 and commented

We'd like to provide an actuator endpoint in Boot for an application's scheduled tasks. We have a pull request to add the functionality but it (ab)uses SchedulingConfigurer to capture a snapshot of the scheduled tasks during startup. There's an ordering issue here as another configurer may schedule tasks that would be missed. We could keep a reference to the configurer and call it whenever the actuator endpoint is called, but this feels like a larger abuse of the configurer callback.

I had hoped that I could just inject ScheduledTaskRegistrar but, while its javadoc describes it as a bean, it doesn't appear to actually be one. It also exposes more than I need; I only to read information about registered tasks, not register additional tasks.

Would it be possible to provide an official API for getting information about any scheduled tasks that have been registered? Perhaps via a bean that can be retrieved from the context if the user has enabled scheduling.


Affects: 5.0 RC4

Reference URL: spring-projects/spring-boot#8831

Issue Links:

  • #20970 ScheduledTaskRegistrar to provide all scheduled tasks with getScheduledTasks()

Referenced from: commits 85baba3, ffd6eff

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 31, 2017

Juergen Hoeller commented

ScheduledTaskRegistrar can be a user-defined bean, populated by bean properties etc, but isn't really meant to expose a unified view of all scheduled tasks. There may be several ScheduledTaskRegistrars in use at runtime, all operating against the same target scheduler, each managing the lifecycle of a particular set of tasks. The better place for an overview of all scheduled tasks might be the target TaskScheduler itself, potentially decorated accordingly in Boot.

Otherwise, for an overview of all @EnableScheduling-driven beans (which might not be the complete set of tasks at runtime but good enough for your purposes), we could also let ScheduledAnnotationBeanPostProcessor expose its scheduled tasks through a corresponding public accessor method. You could then grab the ScheduledAnnotationBeanPostProcessor as a bean by type and call such public introspection methods on it?

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 31, 2017

Andy Wilkinson commented

The better place for an overview of all scheduled tasks might be the target TaskScheduler itself, potentially decorated accordingly in Boot.

That's an interesting idea. Thank you. We don't have any (auto-)configuration for a TaskScheduler in Boot at the moment, but decorating as you suggest when we do sounds look a good avenue to explore.

You could then grab the ScheduledAnnotationBeanPostProcessor as a bean by type and call such public introspection methods on it?

That sounds good. Yes please.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 31, 2017

Juergen Hoeller commented

I've currently got this as a Set<ScheduledTask> getScheduledTasks() method on ScheduledAnnotationBeanPostProcessor, with ScheduledTask exposing a Task getTask() method now. You may check the type of the task then, and for easier discovery, I've also introduced specific FixedRateTask and FixedDelayTask subclasses which you may then check for next to CronTask, not requiring any extra metadata beyond the Task instance itself.

I'll have one more pass through it; to be committed tonight.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Oct 31, 2017

Juergen Hoeller commented

As a bonus, I'm considering a ScheduledTaskHolder interface with Set<ScheduledTask> getScheduledTasks() on it, implemented by ScheduledAnnotationBeanPostProcessor as well as ScheduledTaskRegistrar. This would also make the latter discoverable when defined as an individual bean, providing a more comprehensive overview at runtime by checking for all beans of type ScheduledTaskHolder and exposing an aggregated view for them.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 6, 2017

Juergen Hoeller commented

A first pass is in now, including the ScheduledTaskHolder interface.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 14, 2017

Andy Wilkinson commented

This looks ideal for our purposes. Thank you.

Is there time to sneak in accessors on PeriodicTrigger for its four fields? That would allow us to show periodic triggers with the same details as a fixed-rate or fixed-delay task. CronTrigger already has an accessor for the expression so it would also make things a little more symmetric there.

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 14, 2017

Juergen Hoeller commented

Sure, let's add those for 5.0.2 still...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.