/// <summary> /// Handler of steps sequentially as provided, checking each one for success /// before moving to the next. Returns the last StepExecution /// successfully processed if it exists, and null if none were processed. /// </summary> /// <param name="execution"></param> protected override void DoExecute(JobExecution execution) { StepExecution stepExecution = null; foreach (IStep step in _steps) { stepExecution = HandleStep(step, execution); if (stepExecution.BatchStatus != BatchStatus.Completed) { break; } } // // Update the job status to be the same as the last step // if (stepExecution != null) { if (Logger.IsDebugEnabled) { Logger.Debug("Upgrading JobExecution status: {0}", stepExecution); } execution.UpgradeStatus(stepExecution.BatchStatus); execution.ExitStatus = stepExecution.ExitStatus; } }
/// <summary> /// @see IJobExecutionDao#SynchronizeStatus. /// </summary> /// <param name="jobExecution"></param> public void SynchronizeStatus(JobExecution jobExecution) { JobExecution persistedExecution; if (jobExecution.Id != null && _executionsById.TryGetValue(jobExecution.Id, out persistedExecution) && persistedExecution.Version != jobExecution.Version) { jobExecution.UpgradeStatus(persistedExecution.Status); jobExecution.Version = persistedExecution.Version; } }
/// <summary> /// @see IJobOperator#Abandon . /// </summary> /// <param name="jobExecutionId"></param> /// <returns></returns> public JobExecution Abandon(long jobExecutionId) { JobExecution jobExecution = FindExecutionById(jobExecutionId); if (jobExecution.Status.IsLessThan(BatchStatus.Stopping)) { throw new JobExecutionAlreadyRunningException("JobExecution is running or complete and therefore cannot be aborted"); } _logger.Info("Aborting job execution: {0} ", jobExecution); jobExecution.UpgradeStatus(BatchStatus.Abandoned); jobExecution.EndTime = new DateTime?(); JobRepository.Update(jobExecution); return(jobExecution); }
/// <summary> /// Persists the status and version fields of a job execution. /// The job execution must have already been persisted. /// </summary> /// <param name="jobExecution"></param> public void SynchronizeStatus(JobExecution jobExecution) { using (var scope = new TransactionScope(TransactionScopeOption.Required, TransactionOptions)) { var currentVersion = DbOperator.Query <long>(InsertTablePrefix(CurrentVersionJobExecutionQuery), new Dictionary <string, object> { { "id", jobExecution.Id } }); if (currentVersion != jobExecution.Version) { var status = DbOperator.Query <string>(InsertTablePrefix(GetStatusQuery), new Dictionary <string, object> { { "id", jobExecution.Id } }); jobExecution.UpgradeStatus(BatchStatus.ValueOf(status)); jobExecution.Version = (int?)currentVersion; } scope.Complete(); } }
/// <summary> /// Persists the status and version fields of a job execution. /// The job execution must have already been persisted. /// </summary> /// <param name="jobExecution"></param> public void SynchronizeStatus(JobExecution jobExecution) { using (var scope = new TransactionScope(TransactionScopeOption.Required, TransactionOptions)) { var currentVersion = DbOperator.Query<long>(InsertTablePrefix(CurrentVersionJobExecutionQuery), new Dictionary<string, object> { { "id", jobExecution.Id } }); if (currentVersion != jobExecution.Version) { var status = DbOperator.Query<string>(InsertTablePrefix(GetStatusQuery), new Dictionary<string, object> { { "id", jobExecution.Id } }); jobExecution.UpgradeStatus(BatchStatus.ValueOf(status)); jobExecution.Version = (int?)currentVersion; } scope.Complete(); } }