kotlin - 保留有关失败项目处理的详细信息
问题描述
我有一个运行 TaskletStep 的作业,然后是一个基于块的步骤,然后是另一个 TaskletStep。在每个步骤中,都可能发生错误(以异常的形式)。
基于块的步骤如下所示:
stepBuilderFactory
.get("step2")
.chunk<SomeItem, SomeItem>(1)
.reader(flatFileItemReader)
.processor(itemProcessor)
.writer {}
.faultTolerant()
.skipPolicy { _ , _ -> true } // skip all Exceptions and continue
.taskExecutor(taskExecutor)
.throttleLimit(taskExecutor.corePoolSize)
.build()
整个工作定义:
jobBuilderFactory.get("job1")
.validator(validator())
.preventRestart()
.start(taskletStep1)
.next(step2)
.next(taskletStep2)
.build()
我预计 Spring Batch 会以某种方式获取沿途发生的异常,因此我可以在作业完成处理后创建一个包含它们的报告。查看不同的上下文,还有一些字段应该包含failureExceptions
. 但是,似乎没有这样的信息(尤其是对于分块步骤)。
如果我需要以下信息,什么是一个好方法:
- 在哪个作业执行中发生了什么异常
- 哪个项目是触发它的项目
解决方案
The JobExecution
provides a method to get all failure exceptions that happened during the job. You can use that in a JobExecutionListener#afterJob(JobExecution jobExecution)
to generate your report.
In regards to which items caused the issue, this will depend on where the exception happens (during the read, process or write operation). For this requirement, you can use one of the ItemReadListener
, ItemProcessListener
or ItemWriteListener
to keep record of the those items (For example, by adding them to the job execution context to be able to get access to them in the JobExecutionListener#afterJob
method for your report).
推荐阅读
- maven - Maven 异常“无法解析插件 org.apache.maven.plugins:maven-surefire-plugin:2.12.4 或其依赖项之一”
- python - 命令引发异常:OpusNotLoaded:
- scala - scala中的隐式函数类型如何模拟效果?
- swift - 用一个协议改变两个 VC 值
- python - Singledispatch 装饰器不像宣传的那样工作
- javascript - 如何编写一个 JS 代码来打印 End 值不大于 33 的斐波那契数列。(例如 0112358)
- php - 两个表单相同的页面 - 一个返回 null 另一个工作
- delphi - 有人可以解释一下 TTextureStyle.RenderTarget 吗?
- tensorflow - 在张量流训练期间改变辍学率 - 有可能吗?
- javascript - 在 JavaScript 函数中传递日期值转换为表达式