手动更改Spring Batch元数据表是不是一个坏主意?

编程入门 行业动态 更新时间:2024-10-25 14:32:39
本文介绍了手动更改Spring Batch元数据表是不是一个坏主意?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用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元数据表是不是一个坏主意?

本文发布于:2023-10-16 10:37:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1497324.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:坏主意   数据表   Spring   Batch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!