Announcement Announcement Module
Collapse
No announcement yet.
Restarting a completed job Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      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.

      Comment


      • #4
        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>

        Comment

        Working...
        X