Comments (8)
Sure thing. The versions are as follows: Spring Cloud Task 2.4.3, Spring Batch 4.3.6, Spring Boot 2.7.1.
I also attach the sources of a test application. You can turn on/off the property "spring.cloud.task.batch.fail-on-job-failure" in application.yml, as needed.
Summing up, my concerns/questions are:
TaskJobLauncherApplicationRunner
is a subclass ofJobLauncherApplicationRunner
, but, in addition to exiting with code 1 when the batch fails, it "overrides" the default behavior altogether (calculating job parameters, monitoring job output, etc.). I don't really understand why two different runners are necessary, and if so, what is the difference between them.- In case the only expected behavior is exiting with code 1, auto-configuring a default ExitCodeExceptionMapper with @ConditionalOnMissingBean should be enough, in line with the reference documentation of Spring Cloud Task.
- Indeed, I implemented such a thing in the attached test app (see code snippet below). This class propagates the batch exit status to task exit message, and returns a different exit code depending on the error type.
NOTE: This configuration only works with the default JobLauncherApplicationRunner (fail-on-job-failure=false). For some reason, ApplicationEventPublisher is not autowired to TaskJobLauncherApplicationRunner and thus the application event listener is not called.
public final class BatchExitCodeExceptionMapper implements ApplicationListener<JobExecutionEvent>, ExitCodeExceptionMapper {
private String exitMessage;
@Override
public void onApplicationEvent(JobExecutionEvent event) {
JobExecution execution = event.getJobExecution();
exitMessage = execution.getExitStatus().getExitCode();
if(execution.getStatus().equals(BatchStatus.FAILED)) {
throw new JobFailedException(execution);
}
}
@Override
public int getExitCode(Throwable exception) {
Throwable cause = exception.getCause();
if (cause instanceof JobExecutionException) { // JobExecutionAlreadyRunningException, etc.
return ExitCodes.JOB_LAUNCH_FAILED.ordinal();
} else if (cause instanceof JobFailedException) {
return ExitCodes.JOB_EXECUTION_FAILED.ordinal();
} else {
return ExitCodes.UNKNOWN_ERROR.ordinal();
}
}
@AfterTask
public void onTaskEnd(TaskExecution taskExecution) {
taskExecution.setExitMessage(exitMessage);
}
private enum ExitCodes {
OK,
JOB_EXECUTION_FAILED,
JOB_LAUNCH_FAILED,
UNKNOWN_ERROR
}
}
from spring-cloud-task.
Documentation needs to be updated. TaskJobLauncherApplicationRunner will be updated to match boot's job incrementer functionality.
from spring-cloud-task.
Could you provide the Spring Cloud Task, Spring Batch, and Spring Boot versions where this issue occurred?
Also can you provide a small sample app that exhibits the behavior?
Thank You!
from spring-cloud-task.
Most of the logic from TaskJobLauncherApplicationRunner.execute
seems duplicated from JobLauncherApplicationRunner.execute
. It's structured very differently but I think it's equivalent.
The problem seems to me that JobLauncherApplicationRunner
does not have an extension point that would allow to use the logic in its private method getNextJobParameters
and get access to the JobExecution
s except through the JobExecutionEvent
s.
Maybe Spring Boot is willing to provide such an extension point. Then the duplicated code could be removed without re-building the logic around event listeners.
from spring-cloud-task.
@hpoettker You are correct in that it was created because there was no extension point with JobLauncherApplicationRunner
. But as you discussed here and with your PR, I think we can approach the Boot team about adding it.
from spring-cloud-task.
For some reason, ApplicationEventPublisher is not autowired to TaskJobLauncherApplicationRunner and thus the application event listener is not called.
This is a separate issue. I've opened a PR for it: #889
from spring-cloud-task.
I've updated #888, which now uses the publishing of the JobExecutionEvent
s as extension point.
The new approach works because the default ApplicationEventMulticaster
invokes all listeners synchronously. Therefore, the execution path is very similar to the current. It would stop working if e.g. a multi-threaded executor is used for invoking the listeners. But is this really a problem? An application that uses both the TaskJobLauncherApplicationRunner
and a custom setup for handling ApplicationEvent
s seems unlikely to me.
from spring-cloud-task.
The root cause of this issue is resolved here: 4ea9b9f as it pertains to the JobExecutionEvent. As far as the duplicate it is being discussed on #888 .
from spring-cloud-task.
Related Issues (20)
- Composed Task - Error: 1364-HY000: Field 'CREATE_TIME' doesn't have a default value, individual tasks are working fine HOT 2
- Composed Task Launch arguments - Launch failed HOT 1
- Docs state that EPUBs are produced, but this doc type is no longer produced
- README for Timestamp sample has incorrect name for Spring Cloud Task HOT 1
- Property highlight not not properly rendered in doc HOT 2
- Link to BatchStatus doc points to 4.0.x it should refer to current release HOT 2
- misprint in spring-cloud-task 4.1.0-M2 release HOT 2
- NoSuchMethodError when launch a spring batch worker using DeployerPartitionerHandler on KubernetesDeloyerTaskLaucher HOT 3
- Update link to snapshot documentation HOT 1
- BOOT3 tables not used HOT 2
- use spring.cloud.task.tablePrefix for DefaultTaskConfigurer HOT 2
- Jar versions in the Single Step Batch Job sample readme are out of date HOT 2
- Task observability interferes with task execution listener implementations that also implement the ApplicationRunner interface HOT 2
- Auto-configuration fails when batch enabled and fail-on-job-failure is set HOT 1
- parentExecutionId is null HOT 2
- DefaultTaskConfigurer constructors should use TaskProperties.getTablePrefix() instead of constant TaskProperties.DEFAULT_TABLE_PREFIX HOT 10
- The documentation references old initializr and needs to be updated to avoid confusion. HOT 1
- Fix "รผber-jar" to "Uber-jar" in "getting-started" Documentation.
- Improve documentation on Batch - Task integration, especially regarding datasource and transactionManagers
- Set exit code is not working HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spring-cloud-task.