Automattic\WooCommerce\Internal\PushNotifications\Services
NotificationRetryHandler::handle_retry
ActionScheduler callback for retry jobs.
Reconstructs the notification from the stored identity, then delegates to the processor with is_retry=true.
$extra defaults to empty so retries scheduled before it was added still run, rebuilding a stock notification as low_stock as they always did.
Method of the class: NotificationRetryHandler{}
No Hooks.
Returns
void. Nothing (null).
Usage
$NotificationRetryHandler = new NotificationRetryHandler(); $NotificationRetryHandler->handle_retry( $type, $resource_id, $attempt, $extra ): void;
- $type(string) (required)
- The notification type.
- $resource_id(int) (required)
- The resource ID.
- $attempt(int) (required)
- The current retry attempt number (1-based).
- $extra(array)
- Identity fields from Notification::get_identity_data().
Default:array()
Changelog
| Since 10.8.0 | Introduced. |
NotificationRetryHandler::handle_retry() NotificationRetryHandler::handle retry code WC 11.3.0
public function handle_retry( string $type, int $resource_id, int $attempt, array $extra = array() ): void {
try {
// `+` rather than array_merge for the reason given in
// NotificationProcessor::handle_safety_net().
$notification = Notification::from_array(
array(
'type' => $type,
'resource_id' => $resource_id,
) + $extra
);
} catch ( Exception $e ) {
$this->step_logger->log_unattributed_failure(
'retry',
'invalid_notification',
'error',
sprintf( 'Retry failed: %s', $e->getMessage() ),
array(
'type' => $type,
'resource_id' => $resource_id,
'attempt' => $attempt,
)
);
return;
}
try {
wc_get_container()->get( NotificationProcessor::class )->process(
$notification,
true,
$attempt
);
} catch ( Exception $e ) {
$this->step_logger->log_failure(
$notification,
'retry',
'exception',
'error',
sprintf( 'Retry failed: %s', $e->getMessage() ),
array( 'attempt' => $attempt )
);
$this->schedule( $notification, null, $attempt );
}
}