Announcement Announcement Module
Collapse
No announcement yet.
How to Repeat Job based on parameters Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to Repeat Job based on parameters

    I want to execute my job more than once based on the input parameters. Users will pass month as Job Parameter. If they pass Jan as a month, I should repeat my job from Jan to current month as separate execution. If they are not passing Month Parameter then I should Query the database to get the last execution of this job to find the month and then repeat the same job till current month by passing month as argument to my Job.

    Please help my how to do this with Spring Batch.

    Thanks
    Hari

  • #2
    Wrap the JobLauncher. Your version will query the database, figure out what months need to run, create JobParameters, and pass them to the delegate JobLauncher to run the specific instance of the job.

    The way the framework is designed, you will not be able to use the exact same parameters if the previous execution was COMPLETED. To circumvent this, you can add an additional parameter, the current timestamp, that will ensure that the JobParameters are unique.

    Comment


    • #3
      Thanks for Quick response DHGarrette.

      If I already have few JobParameters in the JobParameters object of JobLauncher Run() method, How can I add new JobParameter at run time. I did not find any method to add new JobParameter to the existing JobParameters object.

      I am trying to convert the given JobParameters object into Properties using DefaultJobParametersConverter and then adding new value to the Properties object and then converting it back to JobParameters object. Is it the right approach. Please let me know.

      Comment


      • #4
        Take a look at the JobParametersBuilder. It should make things easier.

        Comment


        • #5
          Also look at the JobParametersIncrementer and JobOperator interfaces (notably startNextInstance()).

          Comment

          Working...
          X