StripeKit 0.1.1
Stripe integration toolkit for C++
Loading...
Searching...
No Matches
stripekit::InMemoryWebhookDedupStore Class Referencefinal

A de-duplication store that keeps everything in memory. More...

#include <WebhookDedupStore.h>

Inheritance diagram for stripekit::InMemoryWebhookDedupStore:
[legend]

Public Member Functions

 InMemoryWebhookDedupStore ()
 Creates an empty store.
 ~InMemoryWebhookDedupStore () override
 Destroys the store instance.
ClaimResult claim (const ClaimRequest &request) override
 Tries to reserve an event id for processing.
bool mark_processed (std::string_view event_id, std::chrono::system_clock::time_point processed_at) override
 Records that an event has been fully handled.
bool release_claim (std::string_view event_id, std::chrono::system_clock::time_point claimed_at) override
 Releases an unfinished claim after its handler has stopped.
void erase_expired (std::chrono::system_clock::time_point now, std::chrono::hours retention) override
 Deletes records older than the retention period.
Public Member Functions inherited from stripekit::WebhookDedupStore
virtual ~WebhookDedupStore ()=default
 Destroys the store instance.

Detailed Description

A de-duplication store that keeps everything in memory.

Suitable for tests and local development. It forgets everything when the process exits and is not shared between processes, so it is not appropriate for production.

Safe to use from several threads.

Definition at line 169 of file WebhookDedupStore.h.

Constructor & Destructor Documentation

◆ InMemoryWebhookDedupStore()

stripekit::InMemoryWebhookDedupStore::InMemoryWebhookDedupStore ( )

Creates an empty store.

◆ ~InMemoryWebhookDedupStore()

stripekit::InMemoryWebhookDedupStore::~InMemoryWebhookDedupStore ( )
override

Destroys the store instance.

Member Function Documentation

◆ claim()

ClaimResult stripekit::InMemoryWebhookDedupStore::claim ( const ClaimRequest & request)
overridevirtual

Tries to reserve an event id for processing.

Parameters
requestThe event id to reserve, and the timing rules to apply.
Returns
Whether this caller won the reservation.

Implements stripekit::WebhookDedupStore.

◆ mark_processed()

bool stripekit::InMemoryWebhookDedupStore::mark_processed ( std::string_view event_id,
std::chrono::system_clock::time_point processed_at )
overridevirtual

Records that an event has been fully handled.

Parameters
event_idThe event id that was handled.
processed_atWhen it finished.
Returns
True if a claim record was updated.

Implements stripekit::WebhookDedupStore.

◆ release_claim()

bool stripekit::InMemoryWebhookDedupStore::release_claim ( std::string_view event_id,
std::chrono::system_clock::time_point claimed_at )
overridevirtual

Releases an unfinished claim after its handler has stopped.

Delete only the unprocessed record whose claim time matches claimed_at, so an older attempt cannot release a newer worker's reservation.

Parameters
event_idThe event to allow another delivery to retry.
claimed_atThe successful ClaimRequest::now for this attempt.
Returns
True if the matching claim was removed; false if it no longer exists.
Exceptions
StripeKitExceptionThe store could not release the claim.

Implements stripekit::WebhookDedupStore.

◆ erase_expired()

void stripekit::InMemoryWebhookDedupStore::erase_expired ( std::chrono::system_clock::time_point now,
std::chrono::hours retention )
overridevirtual

Deletes records older than the retention period.

Parameters
nowCurrent time.
retentionHow long a record must be kept.

Implements stripekit::WebhookDedupStore.


The documentation for this class was generated from the following file: