Results 1 to 4 of 4

Thread: Restarting a completed job

  1. #1
    Join Date
    Aug 2009
    Posts
    15

    Default Restarting a completed job

    I need to restart a completed job, running under a web application which takes a file as input
    But the job fails to restart once the job successfully completes. I need to rename the file to start the job again.

    I tried allow-start-if-complete="true" in the tasklet

    Is there any way to restart a completed job ?


    -Shriny

  2. #2
    Join Date
    Feb 2008
    Posts
    488

    Default

    You need to give a unique job parameter. An easy way to do this is to use the RunIdIncrementer which just assigns an integer to each job instance and adds one for each new instance.

  3. #3
    Join Date
    May 2007
    Posts
    23

    Default

    xml speaking, here's a configuration example using RunIdIncrementer :

    Code:
    
    <bean id="jobLauncher"
          class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
        <property name="jobRepository" ref="jobRepository"/>
    </bean>
    
    <bean id="jobRepository"
          class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
    <property name="dataSource" ref="testDataSource"/>
    <property name="transactionManager" ref="transactionManager"/>
    </bean>
    
    <bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
    <property name="dataSource" ref="testDataSource"/>
    </bean>
    
    <bean name="jobParamatersIncrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer">
    </bean>
    
     <!-- your specific job should have the incrementer injected-->
    <job id="testJob" xmlns="http://www.springframework.org/schema/batch" restartable="true"
         incrementer="jobParamatersIncrementer"
            >
    ....
    </job>
    For us we use the CommandLineJobRunner to launch the jobs and to be able to use the job incrementer -next option should be specified.

    hope this helps.

  4. #4

    Default

    Quote Originally Posted by souad View Post
    xml speaking, here's a configuration example using RunIdIncrementer :

    Code:
    
    <bean id="jobLauncher"
          class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
        <property name="jobRepository" ref="jobRepository"/>
    </bean>
    
    <bean id="jobRepository"
          class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
    <property name="dataSource" ref="testDataSource"/>
    <property name="transactionManager" ref="transactionManager"/>
    </bean>
    
    <bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
    <property name="dataSource" ref="testDataSource"/>
    </bean>
    
    <bean name="jobParamatersIncrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer">
    </bean>
    
     <!-- your specific job should have the incrementer injected-->
    <job id="testJob" xmlns="http://www.springframework.org/schema/batch" restartable="true"
         incrementer="jobParamatersIncrementer"
            >
    ....
    </job>
    For us we use the CommandLineJobRunner to launch the jobs and to be able to use the job incrementer -next option should be specified.

    hope this helps.
    you can clean the XML up even further w/ the p namespace, etc:

    Code:
    <beans:bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher"
      p:jobRepository-ref="jobRepository"/>
    
    <job-repository id="jobRepository"/>
    
    <beans:bean id="jobExplorer" class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean"
      p:dataSource-ref="testDataSource"/>
    
    <beans:bean id="jobParamatersIncrementer" class="org.springframework.batch.core.launch.support.RunIdIncrementer"/>
    
    <job id="testJob" incrementer="jobParamatersIncrementer">
      ....
    </job>
    --
    Chris

Tags for this Thread

Posting Permissions

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