Skip to main content

Module step

Module step 

Source
Expand description

Step definition and execution.

Contains types for defining and executing steps:

  • Step: Interface for individual units of work
  • StepInstance: Specific instance of a step with configuration
  • StepExecution: Execution details for a step run
  • StepBuilder: Builder for creating step instances

§Step Module

This module provides the core step execution functionality for the Spring Batch framework. A step represents a single phase of a batch job that processes data in chunks or executes a single task (tasklet).

§Overview

The step module supports two main execution patterns:

§Chunk-Oriented Processing

Processes data in configurable chunks using the read-process-write pattern:

  • Reader: Reads items from a data source
  • Processor: Transforms items (optional)
  • Writer: Writes processed items to a destination

§Tasklet Processing

Executes a single task or operation that doesn’t follow the chunk pattern.

§Key Features

  • Error Handling: Configurable skip limits for fault tolerance
  • Metrics Tracking: Comprehensive execution statistics
  • Lifecycle Management: Proper resource management with open/close operations
  • Builder Pattern: Fluent API for step configuration

§Examples

§Basic Chunk-Oriented Step

use spring_batch_rs::core::step::{StepBuilder, StepExecution, Step};
use spring_batch_rs::core::item::{ItemReader, ItemProcessor, ItemWriter};
use spring_batch_rs::BatchError;

// Implement your reader, processor, and writer

let reader = MyReader;
let processor = MyProcessor;
let writer = MyWriter;

let step = StepBuilder::new("my-step")
    .chunk(100)                    // Process 100 items per chunk
    .reader(&reader)
    .processor(&processor)
    .writer(&writer)
    .skip_limit(10)               // Allow up to 10 errors
    .build();

let mut step_execution = StepExecution::new(step.get_name());
let result = step.execute(&mut step_execution);

§Tasklet Step

use spring_batch_rs::core::step::{StepBuilder, StepExecution, RepeatStatus, Step, Tasklet};
use spring_batch_rs::BatchError;


let tasklet = MyTasklet;

let step = StepBuilder::new("my-tasklet-step")
    .tasklet(&tasklet)
    .build();

let mut step_execution = StepExecution::new(step.get_name());
let result = step.execute(&mut step_execution);

Structs§

ChunkOrientedStep
A step implementation that processes items in chunks.
ChunkOrientedStepBuilder
Builder for creating ChunkOrientedStep instances.
StepBuilder
Main entry point for building steps of any type.
StepExecution
Represents the execution context and metrics for a step.
TaskletBuilder
Builder for creating TaskletStep instances.
TaskletStep
A step implementation that executes a single tasklet.

Enums§

BatchStatus
Represents the overall status of a batch job.
ChunkStatus
Represents the status of a chunk during processing.
RepeatStatus
Indicates whether a tasklet should continue executing or has finished.
StepStatus
Represents the current status of a step execution.

Traits§

Step
Core trait that defines the contract for step execution.
Tasklet
A tasklet represents a single task or operation that can be executed as part of a step.