*/ final class Idempotency { /** * Transient-key prefix for the per-event processed marker. * * @since 4.3.0 * @var string */ const TRANSIENT_PREFIX = 'actirise_push_'; /** * Lifetime of a processed marker, in seconds (~1 day). Retries land well * inside this window; the marker expires afterwards so the transient store * does not grow without bound. * * @since 4.3.0 * @var int */ const TTL_SECONDS = 86400; /** * Whether a notification with this event id has already been applied. * * @since 4.3.0 * @param string $event_id The notification event id. * @return bool */ public function is_processed( $event_id ) { return false !== get_transient( self::key( $event_id ) ); } /** * Record that a notification with this event id has been applied. * * Called only after a successful apply so a failed apply is never marked and * remains eligible for retry. * * @since 4.3.0 * @param string $event_id The notification event id. * @return void */ public function mark_processed( $event_id ) { set_transient( self::key( $event_id ), 1, self::TTL_SECONDS ); } /** * Build the transient key for an event id. * * @since 4.3.0 * @param string $event_id The notification event id. * @return string */ private static function key( $event_id ) { return self::TRANSIENT_PREFIX . $event_id; } }