Reputation: 21
I am trying to create a composed task with two tasks running in sequence. These two tasks internally execute spring batch jobs and the job uses job parameters for further processing.
While defining the composed task definition how can we pass the spring batch job parameters?
I am using SCDF CLI to create the composed task definition and expect start_date and end_date to be passed as job params
task create --name server-test-compoesd --definition "server-apn-psp: server --spring.batch.job.names=apnPlacementStatsProcessorJob --start_date=2022-11-20T00:00:00 --end_date=2022-11-22T00:00:00 && server-dbm-psp: server --spring.batch.job.names=dbmPlacementStatsProcessorJob --start_date=2022-11-20T00:00:00 --end_date=2022-11-22T00:00:00"
Here I want to use start_date and end_date as a JobParamter but when I try to execute this task it fails due to Null Pointer Exception because of the absence of start_date and end_date as a job parameter.
Composed task graph
This task runs fine if I manually run the task and give arguments in this way without the --
JobParams accessed in code
public class Test implements Tasklet {
@Value("#{jobParameters['start_date']}")
private String startDate;
@Value("#{jobParameters['end_date']}")
private String endDate;
Version Information SCDF
Core: 2.4.0.RELEASE (Spring Cloud Data Flow Core)
Dashboard: 2.4.0.RELEASE (Spring Cloud Dataflow UI)
Shell: 2.4.0.RELEASE (Spring Cloud Data Flow Shell)
Version Information of spring batch job
spring-boot : 2.5.9
batch-core:4.1.1.RELEASE
How can we pass the job params while defining the composed task ?
Upvotes: 0
Views: 687
Reputation: 306
The quick answer is to use the --arguments
option when launching the application for example: task launch server-test-compoesd --arguments "app.server-apn-psp.0=start_date=2022-11-20T00:00:00 app.server-apn-psp.1=end_date=2022-11-22T00:00:00 app.server-dbm-psp.0=start_date=2022-11-20T00:00:00 app.server-dbm-psp.1=end_date=2022-11-22T00:00:00"
You can read more about launching tasks using arguments here: https://docs.spring.io/spring-cloud-dataflow/docs/current/reference/htmlsingle/#spring-cloud-dataflow-task-launch
The reason the original scenario did not work for you is that when you set start_date
and end_date
in the task definition, these are set as properties. You can read more about setting properties in a task definition here: https://docs.spring.io/spring-cloud-dataflow/docs/current/reference/htmlsingle/#_application_properties_2
Upvotes: 1