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

should be (conveniently) enable/disable tasks based on external property in xml namespace of task [SPR-15228] #19793

Closed
spring-issuemaster opened this issue Feb 7, 2017 · 2 comments
Labels

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Feb 7, 2017

Kunal Patel opened SPR-15228 and commented

As a developer, I would wish to enable/disable scheduled tasks based on some business condition (technically - its external properties or decide behavior programmatically).

Scenarios

  • this is very common behavior in of many business application where you don't want to enable scheduler to schedule a task by default but you wish to have a way to toggle based on external property or programmatically decide to enable or disable.
  • Another common case would be your test case setup - mostly we don't schedule a task instead we mock instead of scheduled-task to populate the state.

Currently we schedule any task like below but AFAIK its not possible to toggle behavior of task (enable/disable).

<task:scheduler id="serviceScheduler" pool-size="1"/>
<task:scheduled-tasks scheduler="serviceScheduler">
          <task:scheduled ref="service" method="scheduledMethod"
                        fixed-delay="${interval:180000}"
                        initial-delay="${start.delay:60000}"/>
</task:scheduled-tasks>

Suggestion
We should be conveniently toggle behavior of task:scheduled using property/value tag in xml (so value can be injected from property placeholders or invoke method to decide behavior programmatically.

Again this is improvement I am suggesting - it can be be taken up based on bandwidth.

Thanks,
/kp


No further details from SPR-15228

@spring-issuemaster
Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Feb 7, 2017

Kunal Patel commented

For the obvious reason accepted answer on this doesn't look clean to me.
http://stackoverflow.com/questions/18406713/how-to-conditionally-enable-or-disable-scheduled-jobs-in-spring

@poutsma
Copy link
Contributor

@poutsma poutsma commented Nov 15, 2019

As stated in that same SO link, this is now possible using Boot's @ConditionalOnProperty.

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.