-
Notifications
You must be signed in to change notification settings - Fork 2.4k
BATCH-2009 - stoppable tasklet #173
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
Conversation
//invoke stop --> reflection? | ||
Tasklet tasklet = ((TaskletStep) step).getTasklet(); | ||
if (tasklet instanceof StoppableTasklet) { | ||
((StoppableTasklet)tasklet).stop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two things here:
- I need to look to see if there is a better way to get a handle on the steps.
- We should only be calling StoppableTasklet#stop() on a tasklet that is actually running. If it is not, that may cause unnecessary exceptions to be thrown.
in reviewing this, is it possible that instead of invoking 'stop' on the Tasklet, we can reuse StepExecution.setTerminateOnly()? (just thinking in text...) |
Unfortunately, the spec requires that a call to JobOperator#stop() call Batchlet#stop() on any currently running batchlets. It is intended to allow for a long running batchlet/tasklet to be interrupted. |
gotcha - thought that was too easy - ok, so i'm changing the logic to something like this;
how does that sound |
Much better. In fact, by getting the running StepExecutions from the JobRepository, you can then get the steps straight from the job (instead of looping through them all). |
have updated the SimpleJobOperator but still not completely satisfied with retrieving the step object. there's just a few too many instanceof/casts in there and the reliance upon AbstractJob rrather than the interface to retrieve the Step object. perhaps we can retrieve from a StepLocator instead? or even the app context directly? |
for (StepExecution stepExecution : jobExecution.getStepExecutions()) { | ||
if (stepExecution.getStatus().isRunning()) { | ||
//have the step execution that's running -> need to 'stop' it | ||
Step step = ((AbstractJob)job).getStep(stepExecution.getStepName()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this works, it would be clearer if it was cast to a StepLocator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
* BATCH-2009: BATCH-2009 - Stoppable tasklet * Added the StoppableTasklet interface (an extension of the Tasklet interface). * Updated JobOperator#stop(long executionId) to call StoppableTasklet#stop() on any currently running tasklets (local executions only). * Updated the SystemCommandTasklet to implement StoppableTasklet
Updated javadoc and whitespace issues. Merged. Thanks! |
No description provided.