Skip to content

Commit 14e0597

Browse files
committed
fix(billing): stop the reminder claim from rewriting stale metadata
Stripe merges metadata on update, so spreading the snapshot read during the list call re-asserted stale values over anything written since. Send only the key being claimed. The claim is not exclusive and the comment no longer says it is: two replicas can still read the same unset marker. Marking before the send only keeps a crash mid-send from resending on the next run.
1 parent f34151b commit 14e0597

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎apps/dokploy/server/utils/trial-notifications.ts‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ const processSubscription = async (
9494
);
9595
const plan = planFromPriceIds(priceIds);
9696

97-
// Claim the reminder before sending so concurrent replicas don't double-send.
97+
// Marked before sending so a crash mid-send cannot resend on the next run.
98+
// Stripe merges metadata, so only the claimed key travels; spreading the
99+
// snapshot read at list time would rewrite concurrent changes.
98100
await stripe.subscriptions.update(subscription.id, {
99-
metadata: { ...subscription.metadata, [threshold.metadataKey]: "sent" },
101+
metadata: { [threshold.metadataKey]: "sent" },
100102
});
101103

102104
try {
@@ -109,7 +111,7 @@ const processSubscription = async (
109111
});
110112
} catch (error) {
111113
await stripe.subscriptions.update(subscription.id, {
112-
metadata: { ...subscription.metadata, [threshold.metadataKey]: "" },
114+
metadata: { [threshold.metadataKey]: "" },
113115
});
114116
throw error;
115117
}

0 commit comments

Comments
 (0)