Skip to content
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

PartitionedHandler: How to pass the step name as an input argument ? #791

Open
nicolasduminil opened this issue Aug 5, 2021 · 1 comment

Comments

@nicolasduminil
Copy link

Hello,

In the partitioned-batch-job project, the partitioned handler is created as follows:

@Bean
public PartitionHandler partitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer, TaskRepository taskRepository) throws Exception {
   ...
  DeployerPartitionHandler partitionHandler = new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, "workerStep");
   ...
  return partitionHandler;
}

How could I pass the step name, here "workerStep", as an input argument. I tried to modify the method like below:

@Bean
public PartitionHandler partitionHandler(TaskLauncher taskLauncher, JobExplorer jobExplorer, TaskRepository taskRepository, String stepName) throws Exception {
   ...
  DeployerPartitionHandler partitionHandler = new DeployerPartitionHandler(taskLauncher, jobExplorer, resource, stepName);
   ...
  return partitionHandler;
}

and I adapted the job/step definition, but it didn't work. I got an exception saying that the method requires a bean of the type String that wasn't found. Then I defined a bean:

@Bean
public String stepName() {
  return new String();
}

and the exception is gone. But I don't think that might be a solution.

Could you please advise ?

Many thanks in advance.

@danilko
Copy link

danilko commented Aug 6, 2021

Hello,

Thought to also share my attempt (and thanks for raising an issue as I was about to do same thing)

I did pass the partitionhandler creation portion (at least it did not error out, and when adding a debugger message, it did get the step name). But faced a null pointer exception within the launchworker (like within your other issue #793)

Reference article I had on StackOverflow with my attempts (in case interested: https://stackoverflow.com/questions/68647761/spring-batch-with-multi-step-spring-cloud-task-partitionhandler-for-remote-p)

I got the job name by using stepContext


    @Bean
    @StepScope
    public PartitionHandler partitionHandler(TaskLauncher taskLauncher,
                                                   JobExplorer jobExplorer,
                                             @Value("#{stepExecution}") StepExecution stepExecution) throws Exception {

        // Then can reference name like
        if(stepExecution.getStepName().equalsIgnoreCase("partitionReaderStep"))
        {
...
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants