Automattic\WooCommerce\Internal\PushNotifications\Services
PendingNotificationStore::record_trigger_times
Persists each pending notification's trigger time to its resource.
Runs on shutdown rather than at trigger time so the write stays out of the order-creation call stack. WordPress fires shutdown on fatal errors too, so the only requests that lose the value are those killed outright (OOM, SIGKILL), the same requests the safety net exists for, and where the payload falls back to the current time.
The recorded time stays that of the first trigger. Core fires the stock hooks on every reduction past the threshold, not only on the crossing, so a product that keeps selling while its notification is in flight would otherwise drag its own recorded time forward and understate its delivery age. The sent marker is checked as well because a send clears the trigger time, so a repeat trigger after one would recreate a value that nothing clears again.
Failures are caught so that a third-party handler on the resource's save hooks cannot stop the dispatch below from running.
Method of the class: PendingNotificationStore{}
No Hooks.
Returns
void. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->record_trigger_times(): void;
Changelog
| Since 11.2.0 | Introduced. |
PendingNotificationStore::record_trigger_times() PendingNotificationStore::record trigger times code WC 11.3.0
private function record_trigger_times(): void {
foreach ( $this->pending as $notification ) {
try {
if ( $notification->has_meta( NotificationProcessor::SENT_META_KEY )
|| $notification->has_meta( NotificationProcessor::TRIGGERED_META_KEY ) ) {
continue;
}
$notification->write_meta(
NotificationProcessor::TRIGGERED_META_KEY,
$notification->get_triggered_at()
);
} catch ( Throwable $e ) {
wc_get_logger()->warning(
sprintf(
'Failed to record push notification trigger time (type=%s, resource_id=%d): %s',
$notification->get_type(),
$notification->get_resource_id(),
$e->getMessage()
),
array( 'source' => PushNotifications::FEATURE_NAME )
);
}
}
}