Automattic\WooCommerce\Internal\PushNotifications\Services
NotificationRetryHandler::schedule
Schedules a retry for a failed notification send.
If the maximum number of retries has been reached, logs a permanent failure instead of scheduling another attempt.
Метод класса: NotificationRetryHandler{}
Хуков нет.
Возвращает
void. Ничего (null).
Использование
$NotificationRetryHandler = new NotificationRetryHandler(); $NotificationRetryHandler->schedule( $notification, ?int $retry_after, $current_attempt ): void;
- $notification(Notification) (обязательный)
- The notification that failed.
- ?int $retry_after(обязательный)
- .
- $current_attempt(int) (обязательный)
- The attempt number that just failed (0-based).
Список изменений
| С версии 10.8.0 | Введена. |
Код NotificationRetryHandler::schedule() NotificationRetryHandler::schedule WC 11.2.2
public function schedule( Notification $notification, ?int $retry_after, int $current_attempt ): void {
$next_attempt = max( 0, $current_attempt ) + 1;
if ( $next_attempt > self::MAX_RETRIES || ! isset( self::BACKOFF_SCHEDULE[ $next_attempt ] ) ) {
wc_get_logger()->error(
sprintf(
'Push notification permanently failed after %d attempts (type=%s, resource_id=%d).',
$next_attempt,
$notification->get_type(),
$notification->get_resource_id()
),
array( 'source' => PushNotifications::FEATURE_NAME )
);
return;
}
$delay = $retry_after ?? self::BACKOFF_SCHEDULE[ $next_attempt ];
if ( $delay > self::MAX_RETRY_DELAY ) {
wc_get_logger()->warning(
sprintf(
'Push notification dropped: retry delay %ds exceeds maximum %ds (type=%s, resource_id=%d).',
$delay,
self::MAX_RETRY_DELAY,
$notification->get_type(),
$notification->get_resource_id()
),
array( 'source' => PushNotifications::FEATURE_NAME )
);
return;
}
as_schedule_single_action(
time() + $delay,
self::RETRY_HOOK,
array(
'type' => $notification->get_type(),
'resource_id' => $notification->get_resource_id(),
'attempt' => $next_attempt,
),
NotificationProcessor::ACTION_SCHEDULER_GROUP,
true
);
}