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

Allowing access to scheduled tasks in the ScheduledTaskRegistrar [SPR-12748] #17345

Closed
spring-issuemaster opened this issue Feb 23, 2015 · 6 comments

Comments

Projects
None yet
2 participants
@spring-issuemaster
Copy link
Collaborator

commented Feb 23, 2015

Tobias Montagna-Hay opened SPR-12748 and commented

I am working on a Spring Batch application and I would like to be able to provide to the users a list of scheduled jobs.

I would like to use the Spring task scheduling features instead of Quartz. At present the ScheduledTaskRegistrar does not have a public API that allows the retrieval of currently scheduled tasks.

Is there a design consideration behind not allowing this to be made available?

I have been able to access the tasks using reflection although this is not an optimal solution.

As a comparison Quartz does make scheduled tasks available via their API. [1]

This is also an issue that other developers are facing.[2],[3]

I have submitted a pull request for a patch that provides this functionality. [4]

[1] http://quartz-scheduler.org/documentation/quartz-2.x/cookbook/ListJobs
[2] http://stackoverflow.com/questions/21791853/how-are-spring-taskscheduled-objects-represented-at-runtime
[3] http://stackoverflow.com/questions/25017691/accessing-scheduled-tasks-in-spring
[4] #745


Affects: 4.1.5

Reference URL: #745

Issue Links:

  • #18255 ScheduledTaskRegistrar's task list getters fail with NPE when no tasks set
  • #18084 Modify creation of the ScheduledTaskRegistrar to be a Spring managed bean
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Feb 26, 2015

Stéphane Nicoll commented

Thanks for the PR!

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 13, 2015

Joris Kuipers commented

I stumbled upon this issue while searching for a way to find out about scheduled tasks when using annotation-based configuration. Even with the committed code I fail to see how one would obtain a reference to the ScheduledTaskRegistrar itself: AFAICT it's a private field of the ScheduledAnnotationBeanPostProcessor and is not exposed in any way other than to SchedulingConfigurer implementations (which are configuration classes not intended for this purpose). Am I missing something?

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 19, 2015

Tobias Montagna-Hay commented

You can access the ScheduledTaskRegistrar by autowiring it into your implementing class. I have provided an example here: http://stackoverflow.com/questions/21791853/how-are-spring-taskscheduled-objects-represented-at-runtime/28753723#28753723

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 20, 2015

Joris Kuipers commented

Thanks Tobias: either this has changed in 4.2 or I simply overlooked something while looking at the relevant Spring code in 4.1.x, as I was pretty sure that the ScheduledTaskRegistrar was never registered as a Spring bean anywhere. As it apparently is, autowiring makes perfect sense.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 20, 2015

Tobias Montagna-Hay commented

It is registered as a ContextLifecycleScheduledTaskRegistrar. This extends the ScheduledTaskRegistrar.

@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

commented Sep 25, 2015

Tobias Montagna-Hay commented

Joris, sorry I set you wrong. This PR only allows XML defined tasks to be inspected.

I have submitted a new issue[1] to see if we can get access to tasks scheduled with annotations enabled.

[1] #18084

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.