2017-05-18 119 views
0

我有三個步驟的彈簧批量作業。第一步運行一次,第二步和第三步爲隊列中的每個項目運行。用於重複步驟即使步驟完成,彈簧批量作業也會失敗

return jobBuilderFactory.get("job") 
     .incrementer(new RunIdIncrementer()) 
     .listener(jobListener()) 
     .flow(step1()) 
     .next(step2()) 
     .next(encrypt()).on("CONTINUE") 
     .to(step2()).on("COMPLETED") 
     .end().end().build(); 

的步驟執行偵聽:作業的代碼

@AfterStep 
@Override 
public ExitStatus afterStep(StepExecution stepExecution) { 
    if (queue.size() > 0) { 
     return new ExitStatus("CONTINUE"); 
    } else { 
     return new ExitStatus("COMPLETED"); 
    } 
} 

的隊列在自動裝配

我的問題是,即使當步驟完成而沒有。退出狀態失敗,作業仍然以失敗退出狀態結束。

我已經調試過它,看看作業是否失敗,因爲一個步驟完成時的退出狀態不是「COMPLETED」,但事實並非如此。

任何想法?我認爲這可能與沒有某個聽衆的步驟之一有關,但我不知道這可能是什麼。如有必要,我可以提供更多代碼。所有的幫助表示讚賞。

日誌跟蹤:

2017-05-18 10:08:10.327 [INFO ] c.d.r.r.BatchApplication - Starting BatchApplication on <computer_name> with PID <pid> 
2017-05-18 10:08:10.329 [DEBUG] c.d.r.r.BatchApplication - Running with Spring Boot v1.4.1.RELEASE, Spring v4.3.3.RELEASE 
2017-05-18 10:08:10.330 [INFO ] c.d.r.r.BatchApplication - The following profiles are active: <profile> 
2017-05-18 10:08:10.367 [INFO ] o.s.c.a.AnnotationConfigApplicationContext - Refreshing org.spring[email protected]163e4e87: startup date [Thu May 18 10:08:10 CDT 2017]; root of context hierarchy 
2017-05-18 10:08:10.891 [WARN ] o.s.c.a.ConfigurationClassEnhancer - @Bean method ScopeConfiguration.stepScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details. 
2017-05-18 10:08:10.899 [WARN ] o.s.c.a.ConfigurationClassEnhancer - @Bean method ScopeConfiguration.jobScope is non-static and returns an object assignable to Spring's BeanFactoryPostProcessor interface. This will result in a failure to process annotations such as @Autowired, @Resource and @PostConstruct within the method's declaring @Configuration class. Add the 'static' modifier to this method to avoid these container lifecycle issues; see @Bean javadoc for complete details. 
2017-05-18 10:08:11.023 [INFO ] c.d.r.config.BaseBatchConfiguration - **************************************************************************** 
2017-05-18 10:08:11.024 [INFO ] c.d.r.config.BaseBatchConfiguration - ********** _____ __ __ _____  _____    __ _  ********** 
2017-05-18 10:08:11.024 [INFO ] c.d.r.config.BaseBatchConfiguration - ********** | __ \| \/ | __ \ /____|   /_(_)  ********** 
2017-05-18 10:08:11.024 [INFO ] c.d.r.config.BaseBatchConfiguration - ********** | |__) | \/| |__) | | |  ___ _ __ | |_ _ __ _ ********** 
2017-05-18 10:08:11.024 [INFO ] c.d.r.config.BaseBatchConfiguration - ********** | _ /| |\/| | ___/ | | /_ \| '_ \| _| |/ _` | ********** 
2017-05-18 10:08:11.024 [INFO ] c.d.r.config.BaseBatchConfiguration - ********** | | \ \| | | | |  | |___| (_) | | | | | | | (_| | ********** 
2017-05-18 10:08:11.024 [INFO ] c.d.r.config.BaseBatchConfiguration - ********** |_| \_\_| |_|_|  \_____\___/|_| |_|_| |_|\__, | ********** 
2017-05-18 10:08:11.024 [INFO ] c.d.r.config.BaseBatchConfiguration - **********             __/ | ********** 
2017-05-18 10:08:11.024 [INFO ] c.d.r.config.BaseBatchConfiguration - **********             |___/ ********** 
2017-05-18 10:08:11.024 [INFO ] c.d.r.config.BaseBatchConfiguration - ********** Property      Value      ********** 
2017-05-18 10:08:11.024 [INFO ] c.d.r.config.BaseBatchConfiguration - ********** --------------------------- ------------------------- ********** 
2017-05-18 10:08:11.024 [INFO ] c.d.r.config.BaseBatchConfiguration - ********** this.profile     <profile>     ********** 
2017-05-18 10:08:11.024 [INFO ] c.d.r.config.BaseBatchConfiguration - ********** files.encrypted    false      ********** 
2017-05-18 10:08:11.025 [INFO ] c.d.r.config.BaseBatchConfiguration - **************************************************************************** 
2017-05-18 10:08:11.363 [INFO ] c.d.r.r.BatchApplication - Calling step1() for the job 
2017-05-18 10:08:11.394 [INFO ] c.d.r.r.BatchApplication - Calling step2() for the job 
2017-05-18 10:08:11.404 [INFO ] c.d.r.r.BatchApplication - Calling job() to begin the job 
2017-05-18 10:08:11.553 [INFO ] o.s.b.a.b.JobLauncherCommandLineRunner - Running default command line with: [--spring.output.ansi.enabled=always, --spring.profiles.active=<profile>] 
2017-05-18 10:08:11.772 [INFO ] o.s.b.c.r.s.JobRepositoryFactoryBean - No database type set, using meta data indicating: MYSQL 
2017-05-18 10:08:11.857 [INFO ] o.s.b.c.l.support.SimpleJobLauncher - No TaskExecutor has been set, defaulting to synchronous executor. 
2017-05-18 10:08:12.232 [INFO ] o.s.b.c.l.support.SimpleJobLauncher - Job: [FlowJob: [name=job]] launched with the following parameters: [{run.id=1, -spring.output.ansi.enabled=always, -spring.profiles.active=<profile>}] 
2017-05-18 10:08:12.310 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:12.313 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****        <APPLICATION_NAME>         ***** 
2017-05-18 10:08:12.313 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****          JOB job STARTING          ***** 
2017-05-18 10:08:12.313 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****           BEGIN JOB PARAMETERS           ***** 
2017-05-18 10:08:12.314 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** Key:          Value:               ***** 
2017-05-18 10:08:12.314 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** ---------------------------------------- ----------------------------------------------------------------- ***** 
2017-05-18 10:08:12.315 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** run.id         1                 ***** 
2017-05-18 10:08:12.315 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** -spring.output.ansi.enabled    always               ***** 
2017-05-18 10:08:12.315 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** -spring.profiles.active     <profile>                ***** 
2017-05-18 10:08:12.315 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:12.316 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:13.055 [INFO ] o.s.b.core.job.SimpleStepHandler - Executing step: [step1] 
2017-05-18 10:08:13.201 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:13.202 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:13.202 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****        STEP step1 STARTING        ***** 
2017-05-18 10:08:13.203 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****           BEGIN STEP PARAMETERS           ***** 
2017-05-18 10:08:13.203 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:13.203 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:13.539 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:13.539 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:13.540 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****     Step step1 FINISHED with status of COMPLETED     ***** 
2017-05-18 10:08:13.540 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** Records Read: 2                      ***** 
2017-05-18 10:08:13.540 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** Records Written: 2                      ***** 
2017-05-18 10:08:13.540 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** Records Skipped: 0                      ***** 
2017-05-18 10:08:13.541 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:13.541 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:13.969 [INFO ] o.s.b.core.job.SimpleStepHandler - Executing step: [step2] 
2017-05-18 10:08:14.025 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:14.026 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:14.026 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****          STEP step2 STARTING          ***** 
2017-05-18 10:08:14.026 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****           BEGIN STEP PARAMETERS           ***** 
2017-05-18 10:08:14.026 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:14.026 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:14.598 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:14.598 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:14.599 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****       Step step2 FINISHED with status of COMPLETED       ***** 
2017-05-18 10:08:14.599 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** Records Read: 3                      ***** 
2017-05-18 10:08:14.599 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** Records Written: 3                      ***** 
2017-05-18 10:08:14.599 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** Records Skipped: 0                      ***** 
2017-05-18 10:08:14.599 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:14.599 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:14.969 [INFO ] o.s.b.core.job.SimpleStepHandler - Executing step: [encrypt] 
2017-05-18 10:08:15.101 [INFO ] c.d.r.encryption.EncryptionTasklet - Output file is: <output_file> 
2017-05-18 10:08:15.101 [DEBUG] c.d.r.encryption.EncryptionTasklet - Configuration value for files.encrypted property: FALSE 
2017-05-18 10:08:15.101 [INFO ] c.d.r.encryption.EncryptionTasklet - Output file is not to be Encrypted 
2017-05-18 10:08:15.411 [INFO ] o.s.b.core.job.SimpleStepHandler - Duplicate step [step2] detected in execution of job=[job]. If either step fails, both will be executed again on restart. 
2017-05-18 10:08:15.531 [INFO ] o.s.b.core.job.SimpleStepHandler - Executing step: [step2] 
2017-05-18 10:08:15.580 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:15.580 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:15.580 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****          STEP step2 STARTING          ***** 
2017-05-18 10:08:15.580 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****           BEGIN STEP PARAMETERS           ***** 
2017-05-18 10:08:15.581 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:15.581 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:19.610 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:19.610 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:19.610 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****       Step step2 FINISHED with status of COMPLETED       ***** 
2017-05-18 10:08:19.610 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** Records Read: 3                      ***** 
2017-05-18 10:08:19.610 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** Records Written: 3                      ***** 
2017-05-18 10:08:19.610 [INFO ] c.d.rmp.listeners.SimpleJobListener - ***** Records Skipped: 0                      ***** 
2017-05-18 10:08:19.611 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:19.611 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:19.945 [INFO ] o.s.b.core.job.SimpleStepHandler - Duplicate step [encrypt] detected in execution of job=[job]. If either step fails, both will be executed again on restart. 
2017-05-18 10:08:20.067 [INFO ] o.s.b.core.job.SimpleStepHandler - Executing step: [encrypt] 
2017-05-18 10:08:20.209 [INFO ] c.d.r.encryption.EncryptionTasklet - Output file is: <output_file> 
2017-05-18 10:08:20.210 [DEBUG] c.d.r.encryption.EncryptionTasklet - Configuration value for files.encrypted property: FALSE 
2017-05-18 10:08:20.210 [INFO ] c.d.r.encryption.EncryptionTasklet - Output file is not to be Encrypted 
2017-05-18 10:08:20.393 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:20.394 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****        R E T U R N M A I L P R O C E S S I N G         ***** 
2017-05-18 10:08:20.394 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****       JOB job FINISHED with status of FAILED        ***** 
2017-05-18 10:08:20.394 [INFO ] c.d.rmp.listeners.SimpleJobListener - *****                           ***** 
2017-05-18 10:08:20.394 [INFO ] c.d.rmp.listeners.SimpleJobListener - ********************************************************************************************************************** 
2017-05-18 10:08:20.451 [INFO ] o.s.b.c.l.support.SimpleJobLauncher - Job: [FlowJob: [name=job]] completed with the following parameters: [{run.id=1, -spring.output.ansi.enabled=always, -spring.profiles.active=<profile>}] and the following status: [FAILED] 
2017-05-18 10:08:20.453 [INFO ] c.d.r.r.BatchApplication - Started BatchApplication in 10.385 seconds (JVM running for 11.111) 
2017-05-18 10:08:20.454 [INFO ] o.s.c.a.AnnotationConfigApplicationContext - Closing org.spring[email protected]163e4e87: startup date [Thu May 18 10:08:10 CDT 2017]; root of context hierarchy 

對不起,該格式是不完美的,我不得不改變在那裏一些名字,以確保有沒有任何敏感信息。

+0

你有一個堆棧跟蹤或任何其他相關框架日誌記錄? –

+0

只需添加日誌追蹤,讓我知道你是否需要其他東西。 – MrWhiteNerdy

+0

你的工作有三個步驟..他第一個2顯示爲完成..第三個呢? tasklet ...返回的狀態是什麼? – Nik

回答

0

經過大量的調試和閱讀Spring Batch的文檔後,我發現如果你想重複步驟,你必須指定所有步驟在作業流程中重複,這樣作業將具有COMPLETED的狀態。

作業流程應該是這樣的:

return jobBuilderFactory.get("job") 
    .incrementer(new RunIdIncrementer()) 
    .listener(jobListener()) 
    .flow(step1()) 
    .next(step2()) 
    .next(encrypt()).on("CONTINUE") 
    .to(step2()) 
    .next(encrypt()).on("COMPLETED") 
    .end().end().build(); 
0

我知道我遲到了,但是這可能仍然幫助。如果您使用的是決勝局以控制流量,而不是一步退出狀態,你可以這樣做如下,要正確結束作業:

Flow syncStrategyFlow = new FlowBuilder<Flow>("syncStrategyFlow") 
      .start(componentsHolder.syncFlowDecider) -- one of the decider is responsible for determining if flow should continue 
       .on(SyncFlowDecider.CONTINUE) 
        .to(componentsHolder.deltaFilterTypeDecider) -- another decider, in this case its responsible for delegating task to specific step 
         .on(DeltaFilterTypeDecider.FILTER_TYPE_JOURNAL) 
          .to(componentsHolder.journalBasedSyncStep) 
          .next(componentsHolder.syncFlowDecider) --call continuation decider 
         .on(DeltaFilterTypeDecider.FILTER_TYPE_UPDATE_DATE) 
          .to(componentsHolder.updateDateBasedSyncStep) 
          .next(componentsHolder.syncFlowDecider) --call continuation decider 
         .on(DeltaFilterTypeDecider.FILTER_TYPE_HASH) 
          .to(componentsHolder.hashBasedSyncStep) 
          .next(componentsHolder.syncFlowDecider) --call continuation decider 
       .on(SyncFlowDecider.COMPLETED) 
        .end() 
      .build(); 

jobBuilderFactory.get("syncJob") 
      .incrementer(new RunIdIncrementer()) 
      .start(syncStrategyFlow) 
      .end() 
      .build(); 
相關問題