SpringBatch – 步骤不再执行:步骤已完成或不可重新启动

huangapple go评论70阅读模式
英文:

SpringBatch - Step no longer executing: Step already complete or not restartable

问题

以下是您提供的内容的翻译部分:

@Bean
public Job databaseCursorJob(@Qualifier("databaseCursorStep") Step exampleJobStep,
                             JobBuilderFactory jobBuilderFactory) {
    return jobBuilderFactory.get("databaseCursorJob")
            .incrementer(new RunIdIncrementer())
            .flow(exampleJobStep)
            .end()
            .build();
}
@Bean
public Job databaseCursorJob(@Qualifier("databaseCursorStep") Step exampleJobStep,
                             JobBuilderFactory jobBuilderFactory) {
    return jobBuilderFactory.get("databaseCursorJob")
            .incrementer(new RunIdIncrementer())
            .flow(exampleJobStep).next(partitionStep())
            .end()
            .build();
}
2020-09-01 14:49:00.260  INFO 6913 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8087 (http) with context path ''
2020-09-01 14:49:00.263  INFO 6913 --- [           main] f.p.r.Application    : Started Application in 7.752 seconds (JVM running for 9.092)
2020-09-01 14:49:00.268  INFO 6913 --- [           main] o.s.b.a.b.JobLauncherCommandLineRunner   : Running default command line with: []
2020-09-01 14:49:00.579  INFO 6913 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : 启动作业: [FlowJob: [name=databaseCursorJob]]参数为: [{}]
2020-09-01 14:49:00.698  INFO 6913 --- [           main] o.s.batch.core.job.SimpleStepHandler     : 步骤已经完成或不可重新启动因此无需执行任何操作: StepExecution: id=120version=4name=databaseCursorStep状态=已完成退出状态=已完成读取计数=1过滤计数=0写入计数=1读取跳过计数=0写入跳过计数=0处理跳过计数=0提交计数=2回滚计数=0退出说明=
2020-09-01 14:49:00.730  INFO 6913 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : 作业: [FlowJob: [name=databaseCursorJob]] 已完成参数为: [{}]状态如下: [已完成]
英文:

I have a single step springbatch application. The job is as follows:

@Bean
public Job databaseCursorJob(@Qualifier("databaseCursorStep") Step exampleJobStep,
JobBuilderFactory jobBuilderFactory) {
return jobBuilderFactory.get("databaseCursorJob")
.incrementer(new RunIdIncrementer())
.flow(exampleJobStep)
.end()
.build();
}

I start the job from a springboot application. This afternoon, I attempted to add a second step to the job. Essentially as follows:

@Bean
public Job databaseCursorJob(@Qualifier("databaseCursorStep") Step exampleJobStep,
JobBuilderFactory jobBuilderFactory) {
return jobBuilderFactory.get("databaseCursorJob")
.incrementer(new RunIdIncrementer())
.flow(exampleJobStep).next(partitionStep())
.end()
.build();
}

In other words, just adding the "next(partitionStep()). However, ever since I did this, the job finishes without executing any step (see shell output below). In fact, even after removing the second step and going back to the original job, it refuses to execute the step. Before attempting to add the second step, I never once encountered this problem. I have gone so far as restarting my VM and it still skips the step. I am rather dead in the water until I resolved this. Grateful for any insights. thanks.

2020-09-01 14:49:00.260  INFO 6913 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8087 (http) with context path ''
2020-09-01 14:49:00.263  INFO 6913 --- [           main] f.p.r.Application    : Started Application in 7.752 seconds (JVM running for 9.092)
2020-09-01 14:49:00.268  INFO 6913 --- [           main] o.s.b.a.b.JobLauncherCommandLineRunner   : Running default command line with: []
2020-09-01 14:49:00.579  INFO 6913 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=databaseCursorJob]] launched with the following parameters: [{}]
2020-09-01 14:49:00.698  INFO 6913 --- [           main] o.s.batch.core.job.SimpleStepHandler     : Step already complete or not restartable, so no action to execute: StepExecution: id=120, version=4, name=databaseCursorStep, status=COMPLETED, exitStatus=COMPLETED, readCount=1, filterCount=0, writeCount=1 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=2, rollbackCount=0, exitDescription=
2020-09-01 14:49:00.730  INFO 6913 --- [           main] o.s.b.c.l.support.SimpleJobLauncher      : Job: [FlowJob: [name=databaseCursorJob]] completed with the following parameters: [{}] and the following status: [COMPLETED]

答案1

得分: 6

我的问题是,如果出现错误或者陷入未知状态,我的工作没有恢复的方式。这一步并没有处于 "已经完成" 的状态,它从未完成过。它的状态仍然是 "已启动",退出代码是 "未知",因为它从未退出过。无论如何,我的工作存储库并不在内存中,而是保存在本地数据库中,这就是为什么即使在重新启动虚拟机后它也无法自行解决的原因(对我来说太丢人了,竟然忘记了这一点)。所以,我通过清除作业实例历史记录来解决了这个问题,但这只是一个权宜之计。我仍然需要修改我的代码,以防止再次发生这种情况。

我还学会了,可以通过检查数据库中的作业存储库来进行诊断(所有信息都在那里)。

我真的解决了这个问题,感谢上面多次回应并指导我的 Hassine 先生,他指引我朝着正确的方向努力。未来防止这种情况发生的解决方案确实在他的第一个回应中提供的链接中得以解决:https://stackoverflow.com/questions/22148117/spring-batch-error-a-job-instance-already-exists-and-runidincrementer-generate

英文:

My issue was that my job had no way recover if there was an error or stuck in an unknown state. The step was not "already complete", it never completed. Its status was still "STARTED", and exit code "UNKNOWN" because it never exited. Anyway, my job repository is not in memory, but captured to a local DB, which is why it never resolved itself even after restarting VM (shame on me for not remembering this). So, I was able to fix by wiping out the job instance history, however that was a band-aid. I still have to fix my code to prevent it from happening again.

I also learned I could diagnose by examining the job repository in the database (its all there).

I really resolved this thanks Mr Hassine who responded above several times and pointed me in the right direction. The solution to prevent in the future is indeed addressed in the link he provided in his first response: https://stackoverflow.com/questions/22148117/spring-batch-error-a-job-instance-already-exists-and-runidincrementer-generate

答案2

得分: 0

我遇到了这个错误,然后我通过允许该步骤再次运行来解决了它

.allowStartIfComplete(true)

在创建步骤时,在build()之前加入这个。
这可能会有所帮助。

英文:

I faced this error and I resolved it by allowing the step to run again

.allowStartIfComplete(true)

Add this while creating a step right before the build();
It might help.

huangapple
  • 本文由 发表于 2020年9月2日 03:13:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/63694023.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定