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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidexecuteStep(PartitionAssignmentTask partitionAssignmentTask) voidvoidPolls the database for partition tasks assigned to this node, claims them, and executes them.voidstart()Starts the partition task polling and execution process when the application is ready.
-
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 theApplicationReadyEvent. It schedules thepollAndExecute()method to run at a fixed rate, as configured in theBatchClusterProperties. -
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:
- Fetches partition tasks assigned to this node from the database.
- If there are tasks to run, updates their status to "CLAIMED" in the database.
- Iterates through the tasks and executes each one in a separate thread using the
TaskExecutor. - For each task:
- Retrieves the
JobExecutionandStepExecutionfrom theJobExplorer. - Sets the step execution status to "STARTED".
- Retrieves the
Stepbean from theApplicationContext. - Executes the step.
- Updates the step execution status to "COMPLETED" or "FAILED", and updates the
JobRepository. - Updates the partition task status in the database to "COMPLETED" or "FAILED".
- Retrieves the
-
executeStep
-
onClusterNodeHeartbeatFail
public void onClusterNodeHeartbeatFail()- Specified by:
onClusterNodeHeartbeatFailin interfaceClusterNodeStatusChangeConditionNotifier
-