/// <summary> /// @see IJobOperator#Stop . /// </summary> /// <param name="executionId"></param> /// <returns></returns> /// <exception cref="NoSuchJobException"> </exception> /// <exception cref="JobExecutionNotRunningException"> </exception> public bool Stop(long executionId) { 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.Status; if (!(status == BatchStatus.Started || status == BatchStatus.Starting)) { throw new JobExecutionNotRunningException( string.Format("JobExecution must be running so that it can be stopped: {0}", jobExecution)); } jobExecution.Status = BatchStatus.Stopping; JobRepository.Update(jobExecution); try { IJob job = JobRegistry.GetJob(jobExecution.JobInstance.JobName); var locator = job as IStepLocator; if (locator != null) { //can only process as StepLocator is the only way to get the step object //get the current stepExecution foreach (StepExecution stepExecution in jobExecution.StepExecutions) { if (stepExecution.BatchStatus.IsRunning()) { try { //have the step execution that's running -> need to 'stop' it IStep step = locator.GetStep(stepExecution.StepName); var taskletStep = step as TaskletStep; if (taskletStep != null) { ITasklet tasklet = taskletStep.Tasklet; var stoppableTasklet = tasklet as IStoppableTasklet; if (stoppableTasklet != null) { StepSynchronizationManager.Register(stepExecution); stoppableTasklet.Stop(); StepSynchronizationManager.Release(); } } } catch (NoSuchStepException e) { _logger.Warn("Step not found {0}", e.Message); } } } } } catch (NoSuchJobException e) { _logger.Warn("Cannot find Job object {0}", e.Message); } return(true); }
/// <summary> /// Releases the most recent StepExecution /// </summary> protected void DoExecutionRelease() { StepSynchronizationManager.Release(); }