Class PartitionedWorkerNodeTasksRunner

java.lang.Object
io.github.jchejarla.springbatch.clustering.polling.PartitionedWorkerNodeTasksRunner
All Implemented Interfaces:
ClusterNodeStatusChangeConditionNotifier

public class PartitionedWorkerNodeTasksRunner extends Object implements ClusterNodeStatusChangeConditionNotifier
This class is responsible for polling the database for partition tasks assigned to the current node and executing them. It runs as a background process, periodically checking for new tasks, claiming them, and then executing the corresponding Spring Batch steps.
Author:
Janardhan Chejarla
  • Constructor Details

    • PartitionedWorkerNodeTasksRunner

      public PartitionedWorkerNodeTasksRunner()
  • Method Details

    • start

      @EventListener(org.springframework.boot.context.event.ApplicationReadyEvent.class) public void start()
      Starts the partition task polling and execution process when the application is ready. This method is triggered by the ApplicationReadyEvent. It schedules the pollAndExecute() method to run at a fixed rate, as configured in the BatchClusterProperties.
    • pollAndExecute

      public void pollAndExecute()
      Polls the database for partition tasks assigned to this node, claims them, and executes them.

      This method performs the following steps:

      1. Fetches partition tasks assigned to this node from the database.
      2. If there are tasks to run, updates their status to "CLAIMED" in the database.
      3. Iterates through the tasks and executes each one in a separate thread using the TaskExecutor.
      4. For each task:
        1. Retrieves the JobExecution and StepExecution from the JobExplorer.
        2. Sets the step execution status to "STARTED".
        3. Retrieves the Step bean from the ApplicationContext.
        4. Executes the step.
        5. Updates the step execution status to "COMPLETED" or "FAILED", and updates the JobRepository.
        6. Updates the partition task status in the database to "COMPLETED" or "FAILED".
    • executeStep

      protected void executeStep(PartitionAssignmentTask partitionAssignmentTask)
    • onClusterNodeHeartbeatFail

      public void onClusterNodeHeartbeatFail()
      Specified by:
      onClusterNodeHeartbeatFail in interface ClusterNodeStatusChangeConditionNotifier