Automattic\WooCommerce\Internal\BatchProcessing

BatchProcessingController::update_processor_state()privateWC 1.0

Update the state for a processor after a batch has completed processing.

Method of the class: BatchProcessingController{}

No Hooks.

Return

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->update_processor_state( $batch_processor, $time_taken, ?\Exception $last_error ): void;
$batch_processor(BatchProcessorInterface) (required)
Batch processor instance.
$time_taken(float) (required)
Time take by the batch to complete processing.
?\Exception $last_error **
-
Default: null

BatchProcessingController::update_processor_state() code WC 9.6.0

private function update_processor_state( BatchProcessorInterface $batch_processor, float $time_taken, ?\Exception $last_error = null ): void {
	$current_status                      = $this->get_process_details( $batch_processor );
	$current_status['total_time_spent'] += $time_taken;
	$current_status['last_error']        = null !== $last_error ? $last_error->getMessage() : null;

	if ( null !== $last_error ) {
		$current_status['recent_failures']    = ( $current_status['recent_failures'] ?? 0 ) + 1;
		$current_status['batch_last_failure'] = current_time( 'mysql' );

		if ( is_null( $current_status['batch_first_failure'] ) ) {
			$current_status['batch_first_failure'] = $current_status['batch_last_failure'];
		}
	} else {
		$current_status['recent_failures']     = 0;
		$current_status['batch_first_failure'] = null;
		$current_status['batch_last_failure']  = null;
	}

	update_option( $this->get_processor_state_option_name( $batch_processor ), $current_status, false );
}