Compatibility When Migrating from CommandLineJobRunner to CommandLineJobOperator
#5213
Replies: 2 comments
-
|
Thank you for reporting this!
That's an oversight, I will fix it.
Same here. I will update the new operator accordingly.
Yes it was intentional and the reason is the following: for this to work: the command line job runner has to be defined as a bean in an application context. But what if I want to use it outside an application context? This is just impossible, note the I will plan that for the next release and update the migration guide accordingly.
Stopping or restarting a job by name was confusing. What if the job has two (or more) different instances running in parallel and you want to stop only one of them? Similarly, what if the job has two failed job instances and you only want to restart a single one? By specifying the execution you want to restart, this ambiguity is not possible. Getting the id of the failed execution is possible with a the |
Beta Was this translation helpful? Give feedback.
-
|
Changed to an issue (#5227) and planned for 6.0.2 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Starting with Spring Batch 6.0.0-M1,
CommandLineJobRunnerwas deprecated andCommandLineJobOperatorwas introduced.We are planning to migrate from
CommandLineJobRunnertoCommandLineJobOperator.However, We found several incompatibilities during migration and are not sure how to handle them.
Could you please explain the reasons for these incompatible changes and how we should migrate?
ExitCodeMapperorJobParametersConverter.1) Error output destination differs when starting a job without required arguments
With
CommandLineJobRunner, if we started a job without arguments such asjobPathorjobIdentifier, the exception was written to the log.With
CommandLineJobOperator, if we start a job without arguments such asjobPathorjobIdentifier, all exceptions are caught insideCommandLineJobOperatorand printed only to the console viaSystem.err.printf.Why was this changed from logging exceptions (in
CommandLineJobRunner) to printing them to standard error (inCommandLineJobOperator)? From an operations/monitoring point of view, exceptions are generally expected to be recorded in logs.Request: printing exceptions only to standard error adds complexity to monitoring. Could you also log these exceptions?
2) Validation exceptions at job startup are not logged
With
CommandLineJobRunner, if validation failed at job startup, the exception was thrown as-is and also logged.With
CommandLineJobOperator, if validation fails at startup, the exception is caught inside thestartmethod and an exit code of 1 is returned.As a result, when validation fails at startup with
CommandLineJobOperator, the exception is neither stored in thebatch_job_executiontable nor written to the log.How can we verify that startup validation is actually running?
Request: please record validation failures in the logs.
Example:
Job definition
TestValidatorcodeRun with the following parameters:
We expect an exception from
TestValidatorto appear in the log (this is whatCommandLineJobRunnerdoes), e.g.:But with
CommandLineJobOperator, the exception fromTestValidatoris not shown, so we cannot confirm validation is working:3) Unable to customize
ExitCodeMapperorJobParametersConverterWith
CommandLineJobRunner, we could customize behavior by defining beans likeExitCodeMapperandJobParametersConverter, for example:With
CommandLineJobOperator, even if we define such beans, behavior does not change.We believe this is due to implementation differences between
CommandLineJobRunner#startandCommandLineJobOperator#main.CommandLineJobRunnerusesApplicationContext.getAutowireCapableBeanFactory().autowireBeanProperties, butCommandLineJobOperatoronly gets three beans (JobOperator,JobRepository,JobRegistry) from the DI container.Because of this, even if
ExitCodeMapperorJobParametersConverterexist as beans, they appear to be ignored byCommandLineJobOperator.Code excerpts:
Were these implementation changes intentional? If so, what was the reasoning?
Request: please allow customization of
ExitCodeMapperandJobParametersConverterwithCommandLineJobOperatoras well.4) Different parameters needed to stop or restart a job
With
CommandLineJobRunner, we could stop or restart a job by specifying eitherjobNameorjobExecutionId.With
CommandLineJobOperator, we can only stop or restart by specifyingjobExecutionId.In practice, the user running the job typically only knows the
jobNamethey provided.If we need to stop or restart a job with
CommandLineJobOperator, we first have to obtain thejobExecutionIdsomehow.What is the recommended way to get
jobExecutionIdfrom the command line?Request: please support stopping and restarting by
jobNamewithCommandLineJobOperatoras well.Beta Was this translation helpful? Give feedback.
All reactions