Issue Details (XML | Word | Printable)

Key: BATCH-532
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Robert Kasanicky
Reporter: Dave Syer
Votes: 1
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
Spring Batch

StepExecutionListener can influence exit status but not status of step execution

Created: 30/Mar/08 04:28 AM   Updated: 07/Aug/08 10:07 AM
Component/s: Core
Affects Version/s: 1.0.0
Fix Version/s: 1.0.1

Time Tracking:
Not Specified


 Description  « Hide
StepExecutionListener can influence exit status but not status of step execution. The exit status can be downgraded from COMPLETE to FAILED by returning FAILED from the afterStep() callback. But the BatchStatus in the stepExecution is unchanged, so it looks as if the step was successful. It's a hard decision to decide how to fix this. I suggest that StepExecutionListener should be allowed to throw an exception to signal a failure, and treat that as a normal way for steps to fail, instead of trying to map exit codes to statuses.


 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Dave Syer added a comment - 31/Mar/08 07:50 AM
The workaround is to change the BatchStatus manually in the StepExecutionListener.

Robert Kasanicky added a comment - 31/Mar/08 10:28 AM
Is this issue really a blocker for 1.0.1? There seems to be a reasonable workaround and the way things work currently is "by design", so I feel like we should leave it for 1.1

Dave Syer added a comment - 31/Mar/08 12:17 PM
It's not a blocker - more like a nice to have for 1.0.1, if it meets the criteria of being quick to implement and not make any changes to APIs. I downgraded it.

Dave Syer added a comment - 01/Apr/08 01:33 AM
Actually, on reflection, the workaround only works if you also set the JobExecution.status to FAILED, otherwise there are going to be issues on restart (the job will think it was successful and it wasn't). That is getting quite ugly for anyone relying on being able to fail a job from a listener. I think it should be possible to fix this without any surprises for anyone else.

Robert Kasanicky added a comment - 01/Apr/08 04:35 AM
In the context of BATCH-529 and BATCH-535 I think the solution is calling afterStep() as the last command in the Step#execute - if listener throws exception it will cause the step to fail in standard way. I'm a bit hesitating to notably change the behavior for 1.0.x, but if we agree the current state is simply a bug rather than feature then the sooner it is fixed the better.

Dave Syer added a comment - 01/Apr/08 04:50 AM
I think it's a bug. Unless anyone disagrees I say we should fix it now.

Ben Hale added a comment - 01/Apr/08 05:21 AM
Agreed

Robert Kasanicky added a comment - 01/Apr/08 06:10 AM
listener.afterStep() call moved from catch block to the end of the try block - exception thrown in listener therefore causes the step to fail.

Hiren Shah added a comment - 15/Apr/08 02:25 PM
I tried throwing the RuntimeException from afterStep of step-2 (so as to terminate the job and not to proceed with step-3). However, this exception gets handled in ItemOrientedStep and continues with the step-3.

//stepExecution.setTerminateOnly(); is commented out.......

Robert Kasanicky added a comment - 16/Apr/08 03:27 AM
@Hiren: are you using the trunk version (note the fix is not included in 1.0.0, it is for 1.0.1)? There are tests that make sure throwing exception in afterStep fails the step, so I believe it works correctly.

Hiren Shah added a comment - 16/Apr/08 08:47 AM
@Robert: Yes, i am using spring-batch-core-1.0.0.jar. Shall i get 1.0.1 or use the manual approach as suggested above?

Robert Kasanicky added a comment - 16/Apr/08 08:59 AM
@Hiren: I'd suggest using the trunk version - 1.0.1 is most likely to be released in less than 2 weeks from now, so you'll be back in safe position using official release reasonably soon.

Hiren Shah added a comment - 16/Apr/08 09:02 AM
Thanks Robert!

Hiren Shah added a comment - 05/May/08 10:28 AM
How do i get the release 1.0.1? I don't see it anywhere?

Robert Kasanicky added a comment - 06/May/08 02:24 AM
The 1.0.1 release should be out today.

Dave Syer added a comment - 07/Aug/08 10:07 AM
Assume closed as resolved and released