Spring Batch在重新启动期间无法获取作业上下文值,其中在失败之前设置了值

时间:2016-03-31 04:36:28

标签: java spring spring-batch spring-batch-admin

我正在使用带有db2服务器的spring batch 3.问题在于使用spring job opertor重新启动失败的作业,来自作业上下文的newFileStatus的值为null。该值用于决定下一步。

if (BatchStatus.STARTED.equals(executions.getStatus())) {
    executions.setEndTime(new Date());
    executions.setStatus(BatchStatus.FAILED);
    executions.setExitStatus(ExitStatus.FAILED);
    jobRepository.update(executions);
    logger.info("Restart Status : Restarted for Start Status ");
    jobOperator.restart(executions.getId());
} else if (BatchStatus.FAILED.equals(executions.getStatus())) {
    loadCache();
    logger.info("Restart Status : Restarted for Failed Status ");
    jobOperator.restart(executions.getId());
} else {// For COMPLETED AND UNKNOWN Status
    //New Run
}

并在tasket中重启后从上下文中获取值

@Override
public ExitStatus afterStep(StepExecution stepExecution) {
    logger.info("Step Execution Status : " +       this.stepExecution.getStatus());
    ExitStatus exitStatus;

    if (this.stepExecution.getStatus().equals(BatchStatus.FAILED)) {
        exitStatus = ExitStatus.FAILED;

    } else if (this.stepExecution.getStatus().equals(BatchStatus.COMPLETED)) {
        ExecutionContext jobContext = stepExecution.getJobExecution().getExecutionContext();
        boolean newFilesStatus = (Boolean) jobContext.get("newFilesArrived");
        //based on newFileStaus next step will be determined
        if(newFilesStatus){
            //return newStep
        }else{
            //skipe new step
        }

    return exitStatus;
}

数据库驱动程序 - StarSql驱动器

谢谢

0 个答案:

没有答案