Results 1 to 4 of 4

Thread: Dynamic/Parameterised jobName?

  1. #1

    Default Dynamic/Parameterised jobName?

    I have a single job definition - myJob. I run an instance of myJob with different parameters for different countries. This works fine but in the job repository when viewed in Spring Batch Admin I have only one entry in the Jobs Tab - myJob. I want to be able to view the statistics for job instances run for France or those run for Germany. I could do this by copying the job definitions and giving each a different name - myJobForFrance, myJobForGermany but this is far from ideal.

    I'd like to be able to do something like
    Code:
    <job id="myJob${job.site}">
    but that's not possible.

    I've looked at the parent/abstract job relationship but it doesn't really do what i want in that it seems to require a lot more config than i need. I just want one job defintion really.

    Any suggestions?
    Last edited by ndw; Sep 30th, 2010 at 10:33 AM.

  2. #2
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    There is a JobRegistry which you can address by name, and what it delivers is actually a Job created by a factory. Maybe you can write a JobFactory that creates a Job with a different name than the one it was registered with? You could also create the Job dynamically in the JobLauncher with a similar abstraction of your own. If I were you I would combine the two - make sure the JobFactory always delivers a fresh mutable instance and then change its name before you launch it. It's not a very common requirement, but I'm sure there will be a workaround there somewhere.

  3. #3

    Default

    Thanks Dave. I started looking into your suggestions and came across GroupAwareJob. From the API doc it looks very much like my requirement - but in my case the 'group' is France rather than financeDepartment.

    I'm creating these by
    Code:
           <bean class="org.springframework.batch.core.configuration.support.JobRegistryBeanPostProcessor">
             ...
            <property name="groupName" value="${batch.groupid}"/>
        </bean>
    Where batch.groupid=France, Germany etc.

    I now see France.myJob and Germany.myJob on the Jobs Tab in SBA.
    Are there any gotchas with this approach, is it a misuse of the 'groupName' attribute?

  4. #4
    Join Date
    Jun 2005
    Posts
    4,232

    Default

    That's pretty much the use case GroupAwareJob is intended for (I had forgotten about it myself). The group name is not set from JobParameters as per your original suggestion, but if that works for you then fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •