在Spring云数据流中运行Batch-Task时的JobInstanceAlreadyCompleteException

时间:2018-04-06 12:27:00

标签: spring spring-batch spring-cloud-dataflow spring-cloud-task

我有一个批处理作业在Spring云数据流中作为任务工作。当我尝试执行相同的任务定义第二次我得到例外:

java.lang.IllegalStateException: Failed to execute CommandLineRunner
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:793)
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:774)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:335)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234)
    at com.tigerbooks.importer.ImportTask.main(ImportTask.java:20)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:48)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:87)
    at org.springframework.boot.loader.Launcher.launch(Launcher.java:50)
    at org.springframework.boot.loader.JarLauncher.main(JarLauncher.java:51)
Caused by: org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException: A job instance already exists and is complete for parameters={-spring.cloud.task.executionid=3, -spring.datasource.username=dataflow_stage, -spring.datasource.url=jdbc:mysql://10.59.254.101:3306/dataflow_staging, -spring.datasource.driverClassName=org.mariadb.jdbc.Driver, -import.import-audio-content=false, -spring.datasource.password=bVs64CMlKvcTdkRLWL2zNPANYD3HMB, -import.syncfolder=/import-integrationtest, -spring.cloud.task.name=Integration-Test, -spring.profiles.active=ftp01,dev}.  If you want to run this job again, change the parameters.
    at org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:130)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:338)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:197)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java

我的工作配置如下所示:

@EnableBatchProcessing
public class JobConfiguration {
    @Bean
    public Job importJob() {
        return jobBuilderFactory.get("Import-Products").incrementer(new RunIdIncrementer())
            .flow(step1())                
            .next(step2())
            .end()
            .build();
    }
}

据我所知,JobParametersIncrementor应该通过向参数添加递增的runId来修复此异常。但在我的情况下,我只能在服务器上运行一次作业,然后我必须清除数据库(mysql)并且RunId在数据库中没有。

1 个答案:

答案 0 :(得分:0)

正如@Michael Minela已经猜到我的工作从错误的docker image-version开始。因此RunIdIncrementer不存在而且不起作用。

使用正确版本注册新应用后,一切正常。感谢。