我正在使用Spring Batch 2.1.8,并按 CommandLineJobRunner 运行作业。例如:
I'm using Spring Batch 2.1.8, and run jobs by CommandLineJobRunner. Such as:
java org.springframework.batch.core.launch.support.CommandLineJobRunner classpath:launchContext.xml theJobId问题
在某些情况下,例如服务器崩溃,运行工作可能会中断。 但是被中断的作业在Spring Batch Meta-Data表中留下了 STARTED 状态,并且无法再次运行。
Problem
At some condition such as a server crash, running job could be interrupted. But the interrupted job left a STARTED status in the Spring Batch Meta-Data tables, and can't be run again.
org.springframework.batch.core.repository.JobExecutionAlreadyRunningException: A job execution for this job is already running我能想到两个解决方案:
I can think of two solutions:
添加一个新的作业参数并每次更改它以使其成为Spring Batch的新作业。例如:
Add a new job parameter and change it everytime to make it a "new" job for Spring Batch. Such as:
java org.springframework.batch.core.launch.support.CommandLineJobRunner classpath:launchContext.xml theJobId times=0当需要重新运行时,请清除所有相应的输出数据,计算次一次,然后重新运行该作业。
And when need to rerun it, do clear all corresponding output data, count up times once, and then rerun the job.
更改手动弹簧批量元数据表。
Change the Spring Batch Meta-Data tables manually.
更新状态以使作业可重新启动。例如:
To update the status to make the job restartable. Such as:
UPDATE BATCH_JOB_EXECUTION SET END_TIME = SYSTIMESTAMP, STATUS = 'FAILED', EXIT_CODE = 'FAILOVER' WHERE JOB_EXECUTION_ID = (SELECT MAX(JOB_EXECUTION_ID) FROM BATCH_JOB_EXECUTION WHERE JOB_INSTANCE_ID = (SELECT MAX(JOB_INSTANCE_ID) FROM BATCH_JOB_INSTANCE WHERE JOB_NAME = 'XXX'));我已经尝试过,看起来效果很好。
I've tried it and it seems works well.
Solution2是个坏主意吗?有没有陷阱?
Is Solution2 a bad idea? Are there any traps?
提前致谢。我们非常感谢任何其他解决方案。
Thanks in advance. And any other solutions are appreciated.
推荐答案解决方案2是目前公认的方法。 API不提供修复此方案的方法。过去有人要求框架自动清理,但99%的情况下,需要做出人为的决定来确定是否真的需要清理。
Solution 2 is the accepted approach right now. The API does not provide a way to fix this scenario. There have been requests in the past for the framework to clean up automatically, but 99% of the time, a human decision is needed to determine if cleanup is truly required.
我对选项2的唯一注意事项是检查BATCH_STEP_EXECUTION表以查看最后执行的步骤的状态。
My only note for option 2 would be to check the BATCH_STEP_EXECUTION table as well to see what state the last executed step was left in.
更多推荐
手动更改Spring Batch元数据表是不是一个坏主意?
发布评论