17#include <unordered_map>
60 std::chrono::system_clock::time_point
now;
130 std::chrono::system_clock::time_point processed_at) = 0;
144 std::chrono::system_clock::time_point claimed_at) = 0;
157 std::chrono::hours retention) = 0;
197 std::chrono::system_clock::time_point processed_at)
override;
201 std::chrono::system_clock::time_point claimed_at)
override;
210 std::chrono::hours retention)
override;
214 bool processed =
false;
215 std::chrono::system_clock::time_point claimed_at;
216 std::chrono::system_clock::time_point processed_at;
220 std::unordered_map<std::string, Entry> records;
~InMemoryWebhookDedupStore() override
Destroys the store instance.
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.
InMemoryWebhookDedupStore()
Creates an empty store.
ClaimResult claim(const ClaimRequest &request) override
Tries to reserve an event id for processing.
void erase_expired(std::chrono::system_clock::time_point now, std::chrono::hours retention) override
Deletes records older than the retention period.
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.
Remembers which webhook events have been 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 ~WebhookDedupStore()=default
Destroys the store instance.
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 void erase_expired(std::chrono::system_clock::time_point now, std::chrono::hours retention)=0
Deletes records older than the retention period.
virtual ClaimResult claim(const ClaimRequest &request)=0
Tries to reserve an event id for processing.
WebhookResponseAction
What to tell Stripe about a delivery.
ClaimOutcome
The result of trying to reserve an event for processing.
WebhookResponseAction map_claim_outcome_to_response(ClaimOutcome outcome)
Works out what to tell Stripe, given a claim outcome.
constexpr std::chrono::minutes defaultStaleInflightTimeout
How long an unfinished claim is honoured before another process may take it.
@ AcknowledgeSuccess
Answer 2xx.
@ RetryableStoreError
The store failed temporarily and the caller should retry.
@ FatalStoreError
The store failed in a non-recoverable way.
@ Claimed
This worker reserved the event id and should process it now.
@ DuplicateProcessed
A previous delivery already completed processing.
@ DuplicateInflight
Another worker is already processing the same event.
Asks the store to reserve an event id.
std::chrono::minutes stale_inflight_timeout
How old an unfinished claim must be before it can be taken over.
std::string event_id
The Stripe event id to reserve.
std::chrono::system_clock::time_point now
Current time, used for claim timestamps and staleness checks.
The store's answer to a ClaimRequest.
bool should_process() const
Reports whether the caller won the reservation.
ClaimOutcome outcome
What happened.
std::string detail
Optional free-form detail from the implementation, for diagnostics.