Example usage for org.springframework.batch.core.scope.context StepContext getJobName

List of usage examples for org.springframework.batch.core.scope.context StepContext getJobName

Introduction

In this page you can find the example usage for org.springframework.batch.core.scope.context StepContext getJobName.

Prototype

public String getJobName() 

Source Link

Document

Convenient accessor for current job name identifier.

Usage

From source file:com.github.jrrdev.mantisbtsync.core.jobs.issues.tasklets.IssuesLastRunExtractorTasklet.java

/**
 * {@inheritDoc}/*from  w  ww .  j av  a 2  s. c  o  m*/
 * @see org.springframework.batch.core.step.tasklet.Tasklet#execute(org.springframework.batch.core.StepContribution, org.springframework.batch.core.scope.context.ChunkContext)
 */
@Override
public RepeatStatus execute(final StepContribution contribution, final ChunkContext chunkContext)
        throws Exception {

    final StepContext stepContext = chunkContext.getStepContext();
    final String jobName = stepContext.getJobName();
    final JobParameters jobParams = stepContext.getStepExecution().getJobParameters();
    final Map<String, JobParameter> currParams = new HashMap<String, JobParameter>(jobParams.getParameters());
    currParams.remove("run.id");

    Date lastJobRun = null;

    final List<JobInstance> jobInstances = jobExplorer.getJobInstances(jobName, 0, 1000);
    for (final JobInstance jobInstance : jobInstances) {
        final List<JobExecution> jobExecutions = jobExplorer.getJobExecutions(jobInstance);
        for (final JobExecution jobExecution : jobExecutions) {

            final JobParameters oldJobParams = jobExecution.getJobParameters();
            final Map<String, JobParameter> oldParams = new HashMap<String, JobParameter>(
                    oldJobParams.getParameters());
            oldParams.remove("run.id");

            if (ExitStatus.COMPLETED.equals(jobExecution.getExitStatus()) && oldParams.equals(currParams)) {

                if (lastJobRun == null || lastJobRun.before(jobExecution.getStartTime())) {
                    lastJobRun = jobExecution.getStartTime();
                }
            }
        }
    }

    if (lastJobRun != null) {
        stepContext.getStepExecution().getExecutionContext().put("mantis.update.last_job_run", lastJobRun);
    }

    stepContext.getStepExecution().getExecutionContext().put("mantis.update.current_job_run",
            Calendar.getInstance());

    return RepeatStatus.FINISHED;
}

From source file:de.codecentric.batch.metrics.AbstractBatchMetricsAspect.java

private String getStepIdentifier() {
    StepContext stepContext = StepSynchronizationManager.getContext();
    StepExecution stepExecution = StepSynchronizationManager.getContext().getStepExecution();
    return stepContext.getJobName() + "." + stepExecution.getStepName();
}