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

  • TaskletStep

    I have a TaskletStep performing FTP. If ftp fails (due to wrong user id) then the execute() returns ExitStatus.CONTINUABLE.

    However, the status field in the BATCH_STEP_EXECUTION shows COMPLETED status. Shouldn't it be FAILED? Also, i was expecting status in BATCH_JOB_EXECUTION table as FAILED. What am i missing here?

    (ExitStatus.FAILED gives the same results....)

  • #2
    Can you just throw an exception from your Tasklet? That should indicate the failure properly.

    Comment


    • #3
      Originally posted by lucasward View Post
      Can you just throw an exception from your Tasklet? That should indicate the failure properly.
      On throwing RuntimeException, from the execute() method, terminates the job immediately and updates the StepExecution status as "FAILED".

      How do i set EXIT_MESSAGE (some customised message) in the batch_step_execution table before throwing this exception? I need to set the customised EXIT_MESSAGE in the table batch_step_execution. I tried "stepExecution.getExitStatus().addExitDescription( "Some mesage");" but doesn't help. (Can throwing an exception in the afterStep help?)

      When to use the status "FAILED", "COMPLETE" and "CONTINUABLE"? What's the significance?
      Last edited by springforever; Apr 26th, 2008, 08:52 AM. Reason: Added the code

      Comment


      • #4
        springforever,

        Did you ever figure this out? If yes, can you please share on how you are propagating return status?

        Thanks!

        Comment


        • #5
          Originally posted by hailspring View Post
          springforever,

          Did you ever figure this out? If yes, can you please share on how you are propagating return status?

          Thanks!
          Actually, i tried using different ways but no luck .

          Waiting to hear something from the experts. Will definitely update you.

          Comment


          • #6
            I think this issue is probably related:

            http://jira.springframework.org/browse/BATCH-532

            Comment


            • #7
              Hi all,

              I wondered if any of you have worked further on this. I am using the 1.1.0.DEV-20080613 version, and I can't seem to get it to work.

              The thing is, that if I don't throw an exception from execute(), then the status is COMPLETED. But if I do throw an exception from execute(), then the class that launches the job won't get the jobExecution.

              If any of you have any ideas, I would like to hear them.

              Thanks in advance.
              Preben

              Comment


              • #8
                I looked a little further on into this. And in my perspective the challenge is, that AbstractStep and SimpleJob updates the status to COMPLETED if no Execption has been thrown. A minor related issue is, that SimpleJobLauncher has the same assumption (no exception = COMPLETED).

                Anyway, I figured that the it might be a fundamental change to the idea of the framework, if ExitStatus is mixed with the jobExecution and stepExecutions status.

                But that is exactly what I want to do. So I have created a JobExecutionListener, that post proces the status of the jobExecution and stepExecutions based on the ExitStatus of the stepExecutions.

                The logic is, that any stepExecution with ExitStatus.FAILED also must be marked af FAILED in the status field. And if any of the steps failed, then the job is marked af failed as well.

                Code:
                public void afterJob(JobExecution jobExecution) 
                {
                	boolean atLeastOneStepFailed = false;
                	Collection<StepExecution> stepExecutions;
                
                	if (null == jobExecution)
                	{
                		return;
                	}
                		
                	stepExecutions = (Collection<StepExecution>)jobExecution.getStepExecutions();
                		
                	if (null != stepExecutions)
                	{
                		for (StepExecution stepExecution : stepExecutions)
                		{
                			ExitStatus exitStatus = stepExecution.getExitStatus();
                			if (ExitStatus.FAILED.getExitCode().equals(exitStatus.getExitCode()))
                			{
                				stepExecution.setStatus(BatchStatus.FAILED);
                				atLeastOneStepFailed = true;
                				jobRepository.saveOrUpdate(stepExecution);
                			}
                		}
                	}
                		
                	if (atLeastOneStepFailed)
                	{
                		jobExecution.setStatus(BatchStatus.FAILED);
                		jobRepository.saveOrUpdate(jobExecution);
                	}
                }

                Comment


                • #9
                  I think you're right that it is something fundamental to the framework. Throwing an Exception from a Step indicates failure, otherwise, returning from execute is assumed to be a successful completion.

                  Preben, I think in your case, launching the Job asynchronously would solve the issue though. You could throw an exception to indicate failure, and use the JobExecution that was returned from the asynchronous invocation of the job, since it will have been updated by the framework.

                  Comment


                  • #10
                    Thanks Lucas,

                    I have reverted to "the true spirit" of Spring Batch:

                    Code:
                    <bean id="simpleAsyncTaskExecutor" class="org.springframework.core.task.SimpleAsyncTaskExecutor"/>
                    
                    <bean id="jobLauncher" class="org.springframework.batch.core.launch.support.SimpleJobLauncher">  
                    	<property name="jobRepository" ref="jobRepository"/>
                    	<property name="taskExecutor" ref="simpleAsyncTaskExecutor"></property>  
                    </bean>
                    And in my code, I simply wait for the jobExecution to finish:

                    Code:
                    jobExecution = launcher.run(job, jobParameters);
                    			
                    while(jobExecution.isRunning())
                    {
                    	Thread.sleep(1000);
                    }

                    Comment

                    Working...
                    X