spring-projects/spring-batch

Consider removing ChunkContext from Tasklet#execute method

Opened this issue · 0 comments

A tasklet is not necessarily chunk-oriented, so having a ChunkContext as a parameter in Tasklet#execute feels strange (if not wrong) to me:

@FunctionalInterface
public interface Tasklet {

	/**
	 * Given the current context in the form of a step contribution, do whatever is
	 * necessary to process this unit inside a transaction. Implementations return
	 * {@link RepeatStatus#FINISHED} if finished. If not they return
	 * {@link RepeatStatus#CONTINUABLE}. On failure throws an exception.
	 * @param contribution mutable state to be passed back to update the current step
	 * execution
	 * @param chunkContext attributes shared between invocations but not between restarts
	 * @return an {@link RepeatStatus} indicating whether processing is continuable.
	 * Returning {@code null} is interpreted as {@link RepeatStatus#FINISHED}
	 * @throws Exception thrown if error occurs during execution.
	 */
	@Nullable
	RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception;

}

The chunk context is documented to hold attributes shared between invocations but not between restarts, but is this really required? This actually violates the ISP for people not using this functionality (ie the parameter won't be used).

If considered, this would be a big breaking change, but it is worth fixing in a major release for a cleaner API design.