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

A de-duplication store that uses a SQLite database. More...

#include <SqliteWebhookDedupStore.h>

Inheritance diagram for stripekit::SqliteWebhookDedupStore:
[legend]

Public Member Functions

 SqliteWebhookDedupStore (std::string database_path)
 Opens or creates the database.
 ~SqliteWebhookDedupStore () override
 Closes the database and destroys the store.
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 uses a SQLite database.

The sensible default for an application running on a single host: unlike InMemoryWebhookDedupStore it survives restarts, and it needs no database server. Applications running several instances should implement WebhookDedupStore against their shared database instead, since separate SQLite files cannot agree on which events are done.

Only available when StripeKit was built with SQLite support; check sqlite_dedup_store_is_available() if that is in doubt.

static stripekit::SqliteWebhookDedupStore dedup_store("stripe-webhooks.sqlite3");
A de-duplication store that uses a SQLite database.

The store must outlive every handler that uses it. Safe to use from several threads.

Definition at line 43 of file SqliteWebhookDedupStore.h.

Constructor & Destructor Documentation

◆ SqliteWebhookDedupStore()

stripekit::SqliteWebhookDedupStore::SqliteWebhookDedupStore ( std::string database_path)
explicit

Opens or creates the database.

Missing tables are created, so a fresh path just works.

Parameters
database_pathPath to the SQLite file. Its directory must exist and be writable, and the file must be on local storage; network filesystems do not give SQLite the locking it needs.
Exceptions
ConfigurationExceptionThe database could not be opened or prepared, or this build has no SQLite support.

◆ ~SqliteWebhookDedupStore()

stripekit::SqliteWebhookDedupStore::~SqliteWebhookDedupStore ( )
override

Closes the database and destroys the store.

Member Function Documentation

◆ claim()

ClaimResult stripekit::SqliteWebhookDedupStore::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::SqliteWebhookDedupStore::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::SqliteWebhookDedupStore::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::SqliteWebhookDedupStore::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. Keep this longer than Stripe's retry window, which runs for several days.

Implements stripekit::WebhookDedupStore.


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