@Override public RepeatStatus execute(final StepContribution sc, final ChunkContext context) throws Exception { log.info("First simple task ..... execute !!! "); log.info("+++ StepContribution : {} ", sc); log.info( "+++ ChunkContext : {} -> jobName : {} ", context, context.getStepContext().getJobName()); log.info( "+++ StepContext : jobParameters : {} , stepExecution : {} , stepName : {} ", context.getStepContext().getJobParameters(), context.getStepContext().getStepExecution(), context.getStepContext().getStepName()); ExecutionContext jobExecutionContext = context.getStepContext().getStepExecution().getJobExecution().getExecutionContext(); JobParameters jobParams = context.getStepContext().getStepExecution().getJobExecution().getJobParameters(); log.info("time : {}", jobParams.getDate("time")); log.info("test : {}", jobParams.getString("test")); log.info("message : {}", message); jobExecutionContext.put("x", "y"); // promote // promote ExecutionContext stepExecutionContext = context.getStepContext().getStepExecution().getJobExecution().getExecutionContext(); stepExecutionContext.put("login", "przodownikR1"); Thread.sleep(4000); return FINISHED; }
public void open(ExecutionContext executionContext) throws ItemStreamException { if (executionContext.containsKey("step2.tickers.page")) { curPage = (Integer) executionContext.get("step2.tickers.page"); } else { executionContext.put("step2.tickers.page", curPage); } }
@Override protected ExitStatus doRead( StepContribution contribution, ExecutionContext context, ExcelRow item) { ExitStatus result = ExitStatus.EXECUTING; LocalDate thresholdDate = getMaxMonthsThresholdDate(item); if (thresholdDate != null) { // We store the threshold date in the context context.put( "threshold.date", Date.from(thresholdDate.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant())); // We keep trace that we've stored something contribution.incrementWriteCount(1); result = COMPLETED_WITH_MAX_MONTHS; } return result; }
@Test public void testExecuteRestart() throws Exception { DefaultJobParametersExtractor jobParametersExtractor = new DefaultJobParametersExtractor(); jobParametersExtractor.setKeys(new String[] {"foo"}); ExecutionContext executionContext = stepExecution.getExecutionContext(); executionContext.put("foo", "bar"); step.setJobParametersExtractor(jobParametersExtractor); step.setJob( new JobSupport("child") { @Override public void execute(JobExecution execution) throws UnexpectedJobExecutionException { assertEquals(1, execution.getJobParameters().getParameters().size()); execution.setStatus(BatchStatus.FAILED); execution.setEndTime(new Date()); jobRepository.update(execution); throw new RuntimeException("FOO"); } @Override public boolean isRestartable() { return true; } }); step.afterPropertiesSet(); step.execute(stepExecution); assertEquals("FOO", stepExecution.getFailureExceptions().get(0).getMessage()); JobExecution jobExecution = stepExecution.getJobExecution(); jobExecution.setEndTime(new Date()); jobRepository.update(jobExecution); jobExecution = jobRepository.createJobExecution("job", new JobParameters()); stepExecution = jobExecution.createStepExecution("step"); // In a restart the surrounding Job would set up the context like this... stepExecution.setExecutionContext(executionContext); jobRepository.add(stepExecution); step.execute(stepExecution); assertEquals("FOO", stepExecution.getFailureExceptions().get(0).getMessage()); }
public static void putIntoJobExecutionContext( ExecutionContext context, String key, Object value) { Gson gson = new Gson(); String valueString = gson.toJson(value); context.put(key, valueString); }
public void update(ExecutionContext executionContext) throws ItemStreamException { executionContext.put("step2.tickers.page", curPage); curPage++; }