Announcement Announcement Module
Collapse
No announcement yet.
Mark steps and job as failed Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Mark steps and job as failed

    Hi,

    I have a job consisting of one step. That step is going through a list of input items and while processing it, it might generate a warning on an item. These warnings are logged. Now I want the step to have ExitStatus "COMPLETED_WITH_WARNINGS" when a warning has been given on one of it's items. After a warning, an operator should be able to rerun that job, so I want to mark the step (and the complete job) as having FAILED. How can I do this?

    In my attempt so far, I created a StepExecutionListener that checks the ExecutionContext for warnings. Since I want to return an ExitStatus I cannot throw an Exception to make the job fail. Therefore, I tried to set the step status with stepExecution.upgradeStatus(BatchStatus.FAILED) before returning a ExitStatus, but that seems not to be the right approach; when a step fails this way, I get an error message "Encountered an error saving batch meta data.This job is now in an unknown state and should not be restarted." (without an exception being logged) and the status of the step execution is STARTED. From an earlier post I also understood it not good to interfere with the status.

    So what is the right way to do this?

    Regards,
    Pieter

  • #2
    i did something like this to update the status of my step. i hope it helps you....

    Code:
    public class PostProcessingCheckListener extends StepExecutionListenerSupport
    		implements StepExecutionListener {
    
    
    	public ExitStatus afterStep(StepExecution stepExecution) {
    			
    		ExitStatus statusAfterStep = super.afterStep(stepExecution);
    		ExitStatus status = stepExecution.getExitStatus();
    		
    		
    		//if super() has status, we should take it into consideration.  
    		//else, just use status from stepExecution
    		if (statusAfterStep != null) {
    			
    			status = status.and(statusAfterStep);
    		}
    			
    		
    		/**
    		 * assert: read count = write count + 1
    		 * 	- this is b/c the footer is read and skipped.
    		 */
    		if (stepExecution.getReadCount() != stepExecution.getWriteCount() + 1) {
    
    			status = status.and(new ExitStatus(ExitStatus.FAILED.getExitCode(),"transaction readCount != writeCount + 1. something did not get inserted. check log files."));
    		}
    		return status;
    	}
    	
    }

    Comment


    • #3
      In your afterStep method if the condition is true you can do something like

      Code:
      return new ExitStatus("COMPLETED WITH WARN");
      An exit status can't be longer than 20 chars actually so your exception is probably coming from there!

      I just have created a Jira issue for this
      http://jira.springframework.org/browse/BATCH-1535

      Comment


      • #4
        Thanks for the help. I reduced the length of the exitstatus code and now the error message is gone. I also wasn't aware that the initial part of the code was used to set the status of the job; returning FAILED_WITH_WARNS makes the job fail. I still call stepExecution.upgradeStatus(BatchStatus.FAILED) to make the step re-runnable and that seems to work, the error is gone now.

        Comment

        Working...
        X