|
StripeKit 0.1.1
Stripe integration toolkit for C++
|
Remembers which webhook events have been handled. More...
#include <WebhookDedupStore.h>
Public Member Functions | |
| virtual | ~WebhookDedupStore ()=default |
| Destroys the store instance. | |
| virtual ClaimResult | claim (const ClaimRequest &request)=0 |
| Tries to reserve an event id for processing. | |
| virtual bool | mark_processed (std::string_view event_id, std::chrono::system_clock::time_point processed_at)=0 |
| Records that an event has been fully handled. | |
| virtual bool | release_claim (std::string_view event_id, std::chrono::system_clock::time_point claimed_at)=0 |
| Releases an unfinished claim after its handler has stopped. | |
| virtual void | erase_expired (std::chrono::system_clock::time_point now, std::chrono::hours retention)=0 |
| Deletes records older than the retention period. | |
Remembers which webhook events have been handled.
Stripe delivers the same event more than once whenever it cannot confirm receipt. This interface skips completed events and reserves unfinished events for one worker at a time. Handlers must still be safe to retry after failure or a crash.
Which implementation to use depends on the deployment. Use InMemoryWebhookDedupStore for tests, SqliteWebhookDedupStore for a single host, and an implementation backed by the application's shared database when several instances handle the same endpoint.
Implementations must be thread-safe, and claim() must be atomic: two instances racing on the same event id must produce exactly one ClaimOutcome::Claimed. A read followed by a write is not sufficient; use the database's conditional insert.
Definition at line 102 of file WebhookDedupStore.h.
|
virtualdefault |
Destroys the store instance.
|
pure virtual |
Tries to reserve an event id for processing.
| request | The event id to reserve, and the timing rules to apply. |
Implemented in stripekit::InMemoryWebhookDedupStore, and stripekit::SqliteWebhookDedupStore.
|
pure virtual |
Records that an event has been fully handled.
Later deliveries of the same event then report ClaimOutcome::DuplicateProcessed.
| event_id | The event id that was handled. |
| processed_at | When it finished. |
Implemented in stripekit::InMemoryWebhookDedupStore, and stripekit::SqliteWebhookDedupStore.
|
pure virtual |
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.
| event_id | The event to allow another delivery to retry. |
| claimed_at | The successful ClaimRequest::now for this attempt. |
| StripeKitException | The store could not release the claim. |
Implemented in stripekit::InMemoryWebhookDedupStore, and stripekit::SqliteWebhookDedupStore.
|
pure virtual |
Deletes records older than the retention period.
Call this periodically to stop the store growing without limit. Keep the retention comfortably longer than Stripe's retry window, which runs for several days, or an old event could be processed a second time.
| now | Current time. |
| retention | How long a record must be kept. |
Implemented in stripekit::InMemoryWebhookDedupStore, and stripekit::SqliteWebhookDedupStore.