Skip to content

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

Closed
wants to merge 5 commits into from

Conversation

willschipp
Copy link
Contributor

No description provided.

//invoke stop --> reflection?
Tasklet tasklet = ((TaskletStep) step).getTasklet();
if (tasklet instanceof StoppableTasklet) {
((StoppableTasklet)tasklet).stop();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two things here:

  1. I need to look to see if there is a better way to get a handle on the steps.
  2. 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.

@willschipp
Copy link
Contributor Author

in reviewing this, is it possible that instead of invoking 'stop' on the Tasklet, we can reuse StepExecution.setTerminateOnly()? (just thinking in text...)

@mminella
Copy link
Member

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.

@willschipp
Copy link
Contributor Author

gotcha - thought that was too easy - ok, so i'm changing the logic to something like this;

  • get the step executions for this this job
  • check if the stepexecution is running
  • (need to then retrieve the tasklet for this execution and invoke stop())

how does that sound

@mminella
Copy link
Member

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).

@willschipp
Copy link
Contributor Author

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());
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

mminella added a commit that referenced this pull request Aug 5, 2013
* 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
@mminella
Copy link
Member

mminella commented Aug 5, 2013

Updated javadoc and whitespace issues. Merged. Thanks!

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

Successfully merging this pull request may close these issues.

2 participants