Skip to content

Make use of Batch 4.0 M4's new API for accessing job parameters #10135

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
diegolovison opened this issue Aug 31, 2017 · 9 comments
Closed

Make use of Batch 4.0 M4's new API for accessing job parameters #10135

diegolovison opened this issue Aug 31, 2017 · 9 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@diegolovison
Copy link

We are building an application that have dozens jobs.
Each job is configured to run in a scheduled way.

@Autowired
private JobLauncher jobLauncher;

@Scheduled(cron = "0 0/5 * * * ?")
public void run() throws Exception {

    jobLauncher.run(myJob(), new JobParameters());
}

@Bean
public Job myJob() {
    return jobBuilders.get("myJob")
        .incrementer(new RunIdIncrementer())
        .flow(jobStep1())
        .end()
        .build();
}

In this case, "myJob" will run once because we need to properly configure the JobParameters.

There is an excelent example how to propertly configure the parameters in the class JobLauncherCommandLineRunner.

What I am suggesting here is split the logic in the class JobLauncherCommandLineRunner.
Creating another class like "FooJobLauncher" that will have the business logic to execute the job getting the next parameter.
The class JobLauncherCommandLineRunner will use the "FooJobLauncher".

In this way I can autowired "FooJobLauncher" in my class without worrying with the next parameters logic.

I can create a merge request if the team agree with the change. I only need to know a better name for "FooJobLauncher".

Thanks

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Aug 31, 2017
@wilkinsona
Copy link
Member

I'm not 100% sure I've understood which logic it is that you'd like to be able to reuse. Is it what's done in getNextJobParameters(Job, JobParameters)? That, to me, looks like a good candidate for factoring out into a separate class, particularly as it's the only place in JobLauncherCommandLineRunner that makes use of the JobExplorer field.

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Sep 1, 2017
@dsyer
Copy link
Member

dsyer commented Sep 1, 2017

I think @wilkinsona is correct - the OP wants to split out the logic in JobLauncherCommandLineRunner.getNextJobParameters(Job, JobParameters) so he can use it in his own @Scheduled method.
It's a private method with some useful logic, and arguably it ought to be in Spring Batch, but Batch usually pushes these kinds of things off to users, so maybe it is better here.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Sep 1, 2017
@wilkinsona
Copy link
Member

Thanks, @dsyer. @mminella what do you think? Is this method something that you could add to Batch, or do you think it's better-suited to living in Boot or the user's own code?

@wilkinsona wilkinsona added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Sep 1, 2017
@spring-projects-issues
Copy link
Collaborator

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@spring-projects-issues spring-projects-issues added the status: feedback-reminder We've sent a reminder that we need additional information before we can continue label Sep 8, 2017
@mminella
Copy link
Member

mminella commented Sep 8, 2017

I'm fine with pulling this into batch. And 4.0 would be a good opportunity to do so. I've created this Jira item to track us moving it over: https://jira.spring.io/browse/BATCH-2640

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue status: feedback-reminder We've sent a reminder that we need additional information before we can continue labels Sep 8, 2017
@wilkinsona
Copy link
Member

Neat. Thanks, @mminella. Let's use this issue to move onto the Batch-provided version of what's currently in Boot.

@wilkinsona wilkinsona changed the title Split JobLauncherCommandLineRunner business logic Make use of Batch 4.0 M4's new API for accessing job parameters Sep 8, 2017
@wilkinsona wilkinsona added priority: normal type: enhancement A general enhancement and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Sep 8, 2017
@wilkinsona wilkinsona added this to the 2.0.0.M5 milestone Sep 8, 2017
@diegolovison
Copy link
Author

diegolovison commented Sep 20, 2017

The private method JobParameters merge(JobParameters parameters, Map<String, JobParameter> additionals) on class JobLauncherCommandLineRunner is a good candidate to be public as well.

@wilkinsona
Copy link
Member

@diegolovison To reduce the chance of it being missed, I'd recommend making that suggestion on BATCH-2640. It's tracking the Spring Batch changes.

@philwebb philwebb modified the milestones: 2.0.0.M5, 2.0.0.RC1, 2.0.0.M6 Sep 20, 2017
@mminella
Copy link
Member

Just an update, I just merged BATCH-2640. FYI, the merge capability is already available on the JobParametersBuilder which is where we added this functionality.

@snicoll snicoll self-assigned this Oct 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

7 participants