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

Add StepExecution parameter to StoppableTasklet.stop() #4703

Open
andrianov17 opened this issue Nov 10, 2024 · 2 comments · May be fixed by #4715
Open

Add StepExecution parameter to StoppableTasklet.stop() #4703

andrianov17 opened this issue Nov 10, 2024 · 2 comments · May be fixed by #4715

Comments

@andrianov17
Copy link

Currently, StoppableTasklet.stop() doesn't take any parameters. So, from within tasklet it is impossible to distinguish which exactly step execution is requested to stop out of multiple job executions running. This is important when some external request needs to be executed from StoppableTasklet.stop().

Looking into SimpleJobOperator.stop(long executionId) implementation, it looks very straightforward to implement this request - just pass stepExecution to the tasklet stop() method:

@Override
	public boolean stop(long executionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException {

		JobExecution jobExecution = findExecutionById(executionId);
		// Indicate the execution should be stopped by setting it's status to
		// 'STOPPING'. It is assumed that
		// the step implementation will check this status at chunk boundaries.
		BatchStatus status = jobExecution.getStatus();
		if (!(status == BatchStatus.STARTED || status == BatchStatus.STARTING)) {
			throw new JobExecutionNotRunningException(
					"JobExecution must be running so that it can be stopped: " + jobExecution);
		}
		jobExecution.setStatus(BatchStatus.STOPPING);
		jobRepository.update(jobExecution);

		try {
			Job job = jobRegistry.getJob(jobExecution.getJobInstance().getJobName());
			if (job instanceof StepLocator) {// can only process as StepLocator is the
												// only way to get the step object
				// get the current stepExecution
				for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
					if (stepExecution.getStatus().isRunning()) {
						try {
							// have the step execution that's running -> need to 'stop' it
							Step step = ((StepLocator) job).getStep(stepExecution.getStepName());
							if (step instanceof TaskletStep) {
								Tasklet tasklet = ((TaskletStep) step).getTasklet();
								if (tasklet instanceof StoppableTasklet) {
									StepSynchronizationManager.register(stepExecution);
									((StoppableTasklet) tasklet).stop(**stepExecution**);
									StepSynchronizationManager.release();
								}
							}
						}

Thank you in advance!

@andrianov17 andrianov17 added the status: waiting-for-triage Issues that we did not analyse yet label Nov 10, 2024
@fmbenhassine fmbenhassine added type: feature in: core and removed status: waiting-for-triage Issues that we did not analyse yet labels Nov 11, 2024
@fmbenhassine fmbenhassine added this to the 6.0.0 milestone Nov 11, 2024
@HyunSangHan
Copy link

Can I work on this issue?

@HyunSangHan
Copy link

I have submitted a PR!: #4715

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