Announcement Announcement Module
Collapse
No announcement yet.
Re-using the jobs Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Re-using the jobs

    I have created the job defination for specific type of data transfer. Like Database-Database. I have number of different batches which uses this job with various combinations of databases.

    I define a re-usable project where the config file provide the databse details and queries to be used by job for transfer. The problem here, as the same job.xml will be used with different parmeters, I am not able to use the jobExplorer as for all the batches the job ID will be same in repository.

    For Example i have define one job to sync two databases -

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:batch="http://www.springframework.org/schema/batch"
    	xmlns="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"
    	xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"
    	xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.0.xsd
            http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
            http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd">
    
    	<import resource="../../applicationcontext.xml" />
    	<import resource="F2DBeans.xml" />
    	<import resource="F2DExtrenalTableBeans.xml" />
    		
    	<batch:job id="DBSync" job-repository="simpleJobRepository"
    		restartable="true">
    
       <batch:step id="lastRunJobDetails" parent="simpleStep">
                <batch:tasklet ref="getLastJobRunDetails" />
                <batch:next on="COMPLETED" to="deleteData" />
                <batch:end on="FAILED" />
            </batch:step>
    
    
            
    		<batch:step id="deleteData" parent="simpleStep">
    			<batch:tasklet transaction-manager="transactionManager">
    				<batch:chunk reader="deleteItemReader" writer="deleteWriter" skip-limit="1000000">
    				<batch:skippable-exception-classes>
                            java.sql.SQLException
                        </batch:skippable-exception-classes>
    				</batch:chunk>
    				<batch:listeners>
    					<batch:listener ref="deleteMailListener" />
    					<batch:listener ref="baseSkipListener" />
    					<batch:listener ref="baseCDSItemWriteListener" />
    				</batch:listeners>
    			</batch:tasklet>
    			<batch:next on="COMPLETED" to="updateData" />
    			<batch:end on="FAILED" />
    		</batch:step>
    
    		<batch:step id="updateData" parent="simpleStep">
    			<batch:tasklet transaction-manager="transactionManager">
    				<batch:chunk reader="updateItemReader" writer="updateWriter" skip-limit="1000000">
    				<batch:skippable-exception-classes>
                            java.sql.SQLException
                        </batch:skippable-exception-classes>
    				</batch:chunk>
    				<batch:listeners>
    					<batch:listener ref="updateMailListener" />
    					<batch:listener ref="baseSkipListener" />
    					<batch:listener ref="baseCDSItemWriteListener" />
    				</batch:listeners>
    			</batch:tasklet>
    			<batch:next on="COMPLETED" to="insertData" />
    			<batch:end on="FAILED" />
    		</batch:step>
    
    		<batch:step id="insertData" parent="simpleStep">
    			<batch:tasklet transaction-manager="transactionManager">
    				<batch:chunk reader="insertItemReader" writer="insertWriter" skip-limit="1000000">
    				<batch:skippable-exception-classes>
                            java.sql.SQLException
                        </batch:skippable-exception-classes>
    				</batch:chunk>
    				<batch:listeners>
    					<batch:listener ref="insertMailListener" />
    					<batch:listener ref="baseSkipListener" />
    					<batch:listener ref="baseCDSItemWriteListener" />
    				</batch:listeners>
    			</batch:tasklet>
                <batch:next on="COMPLETED" to="decisionStep" />
                <batch:end on="FAILED" />			
    		</batch:step>		
    
    
    		<batch:step id="decisionStep" parent="simpleStep">
    			<batch:tasklet ref="decisionTasklet" />
    		</batch:step>
    
    		<batch:listeners>
    			<batch:listener ref="baseAuditListener" />
    		</batch:listeners>
    
    	</batch:job>
    			
    </beans>

    This job is used by different batches. I can run them with different job parameters. But if you see step lastRunJobDetails that uses the job Explorer to get the last run end point. This fails as all the batches will have same job name (DBSync) in Job Instance table and then i am not able to distinguish between one batch to other.


    Is there any way the either the job ID (DBSync in above example) is passed dynamically or i can derive a dummy job based on this job that will not have any step but will execute the steps from parent?
    Last edited by vinvh; Aug 19th, 2010, 09:18 PM.

  • #2
    could you post here getLastJobRunDetails tasklet implementation? and describe what you want to achieve?

    Comment


    • #3
      Originally posted by vinvh View Post
      Is there any way the either the job ID (DBSync in above example) is passed dynamically or i can derive a dummy job based on this job that will not have any step but will execute the steps from parent?
      Code:
      <batch:job id="unique" parent="DBSync"/>
      should work I think. But if you can do that then you could also just add a unique job parameter (a business key) to the instances as you launch them, and use that to identify the last execution.

      Comment


      • #4
        Thanks for the replies!

        I resolve this issue by overwritting the job name just befor launching the job from job launcher.

        Comment

        Working...
        X