Announcement Announcement Module
Collapse
No announcement yet.
How to bypass NoWorkFoundException Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to bypass NoWorkFoundException

    Hi,

    My job has 3 steps:
    step-1 : update table_A records with some data
    step-2 : generate output file_X from table_A based on criteria_1
    step-3: generate output file_Y from table_A based on criteria_2

    step-2; step-3 are using IbatisDrivingQueryItemReader as the reader.

    The problem is, if step-2 returns no result then the reader will throw NoWorkFoundException and stop the whole job.process. In our domain, it's ok to skip step-2 and shld still proceed to step-3 and vice versa.

    I dont want to seperate step-2; step-3 as a seperate job. Can I achive this? pls advice, thx a lot!
    Last edited by catsfelix; Apr 28th, 2008, 12:10 AM.

  • #2
    I just saw there's a jira issue created for this:
    http://jira.springframework.org/browse/BATCH-414

    thx for the effort of treating this as an outstanding task for the spring-batch team . Meanwhile, as the outcome might not be so soon...I am open to any suggestion that can be done as a work around for this issue. I've checked the spring-batch source code and still am not sure which part I shld extend or overwrites to solve this..

    Comment


    • #3
      I think you may have to wrap the ItemReader/Stream in your own version that delegates method executions and protects the caller from the NoWorkFoundException. The step and job implementations are quite strict on exceptions outside normal "business logic" (e.g. in this case in the open() method of an ItemStream).

      N.B. There will be some changes here in 1.1 (http://jira.springframework.org/browse/BATCH-414), so anything you do now is probably a workaround.

      Comment


      • #4
        Dave, thank you so much for your valuable advice..and yes it solves my problem. Here is what I do to solve the problem:

        Code:
        public class NoWorkFriendlyItemReader extends IbatisDrivingQueryItemReader{
        
        	private static Log log = LogFactory.getLog(NoWorkFriendlyItemReader.class);
        	
        	private boolean noWorkFound= false;
        	
        	public void open(ExecutionContext executionContext) {
        		try{
        			super.open(executionContext);
        		}catch(NoWorkFoundException e){
        			log.info("no work found, skipping to the next step if any");
        			noWorkFound= true;
        		}
        	}
        
        	public Object read() {
        		if(noWorkFound)
        			return null;
        		else
        			return super.read();
        	}
        }
        I created NoWorkFriendlyItemReader that will simply return null in case if there's no work found. It solves my problem but if anyone have a comments or better approach, I would love to hear it from you.

        IMHO, this shld be the default behaviour for the batchjob framework or probably we shld put it as a configurable behaviour. It would be lovely if we hv something like this:

        Code:
         
        ... 
          <bean id="step-2" parent="simpleStep">
             ...
             <property name="errorOnNoWorkFound" value="false"/>
          </bean>
        ...
        Thank you once again and I can't wait for the ver.1.1 to release soon
        Last edited by catsfelix; Apr 28th, 2008, 03:21 AM.

        Comment

        Working...
        X