[英]Exit Spring Batch Job within tasklet
I have a Spring Batch tasklet and I can't figure out how to fail from it. 我有一个Spring Batch Tasklet,但我不知道如何从中失败。 I want to check for certain parameters and if they aren't there, fail the job out on that step.
我要检查某些参数,如果不存在,请在该步骤中使作业失败。
@Component
public class Tfp211SetupTasklet extends AbstractSetupTasklet {
final static Logger LOGGER = LoggerFactory.getLogger(Tfp211SetupTasklet.class);
@Override
protected RepeatStatus performTask(ExecutionContext ec, ChunkContext chunkContext) {
//TODO
//add error checking. If the parameter is not there, fail out or throw an error message.
Map<String, String> params = new HashMap<>();
List<String> requiredParams = new ArrayList<>();
requiredParams.add("name");
requiredParams.add("id");
requiredParams.add("test");
JobParameters jobParameters = chunkContext.getStepContext().getStepExecution().getJobParameters();
params.put("name", jobParameters.getString("name"));
params.put("id", jobParameters.getString("id"));
params.put("test", jobParameters.getString("test"));
// if (!params.values().containsAll(requiredParams)) {
// LOGGER.info("not all required parameters exist for the job execution to succeed.");
// return RepeatStatus.FINISHED;
// }
ec.put(AbstractSetupTasklet.BATCH_PROGRAM_PARAMS, params);
ec.put(AbstractSetupTasklet.BATCH_PROGRAM_NAME, NTfp211.class.getSimpleName());
return RepeatStatus.FINISHED;
}
}
The commented out lines are what I've tried to get the job to exit. 注释掉的行是我试图让工作退出的内容。 Anyone had experience with this?
任何人都有经验吗?
要使小任务失败,只需从其抛出异常即可。
you can implements
interface StepExecutionListener
, and in 您可以
implements
接口StepExecutionListener
,并在
@Override
public ExitStatus afterStep(StepExecution stepExecution) {
// check failed condition
return ExitStatus.FAILED;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.