英文:
How to set ExitStatus of aborted job to "reason for abort" message?
问题
I need to abort a running job and set its ExitStatus
to "reason for abort".
It's quite easy to abort a running job:
try {
if (jobOperator.stop(jobExecutionId)) {
jobOperator.abandon(jobExecutionId);
log.info("The job with JobId :" + jobExecutionId + " was canceled.");
}
}
And yes, I know, the only way to set the ExitStatus
is to use AfterJob
in JobExecutionListener
(https://stackoverflow.com/questions/30106218/setting-exit-message-in-batch-job-execution)
But how can I transfer "reason for abort" message from the code that abort the job to JobExecutionListener
's AfterJob
?
英文:
I need to abort a running job and set its ExitStatus
to "reason for abort".
It's quite easy to abort a running job:
try {
if (jobOperator.stop(jobExecutionId)) {
jobOperator.abandon(jobExecutionId);
log.info("The job with JobId :" + jobExecutionId + " was canceled.");
}
}
And yes, I know, the only way to set the ExitStatus
is to use AfterJob
in JobExecutionListener
(https://stackoverflow.com/questions/30106218/setting-exit-message-in-batch-job-execution)
But how can I transfer "reason for abort" message from the code that abort the job to JobExecutionListener
's AfterJob
?
答案1
得分: 1
无法将“中止原因”消息从中止作业的代码传递到JobExecutionListener的AfterJob方法中。你只能从“外部”(通过作业操作者)传递停止信号到“内部”(作业执行及其监听器)。其他所有操作都可以在停止或中止作业后在作业执行本身中完成,类似于:
try {
if (jobOperator.stop(jobExecutionId)) {
jobOperator.abandon(jobExecutionId);
JobExecution jobExecution = jobExplorer.getJobExecution(jobExecutionId);
jobExecution.setExitStatus(new ExitStatus("ABORTED", "中止原因"));
jobRepository.update(jobExecution);
log.info("作业ID为:" + jobExecutionId + " 的作业已被取消。");
}
}
英文:
> how can I transfer "reason for abort" message from the code that abort the job to JobExecutionListener's AfterJob?
There is no way to do that. The only information that you can pass from the "outside" (through the job operator) to the "inside" (the job execution and its listeners) is the stop signal.
Everything else can be done on the job execution itself after stopping or aborting it, something like:
try {
if (jobOperator.stop(jobExecutionId)) {
jobOperator.abandon(jobExecutionId);
JobExecution jobExecution = jobExplorer.getJobExecution(jobExecutionId);
jobExecution.setExitStatus(new ExitStatus("ABORTED", "reason for abort"));
jobRepository.update(jobExecution);
log.info("The job with JobId :" + jobExecutionId + " was canceled.");
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论