Skip to content

Commit

Permalink
fixed retry attempts duplicating exact orders
Browse files Browse the repository at this point in the history
  • Loading branch information
RafidMuhymin committed Nov 6, 2023
1 parent 64e47c3 commit ee46a20
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
12 changes: 10 additions & 2 deletions src/utils/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ export default new Proxy(
},
) as Context;

export async function setupContext(id: string) {
key = await hash(id, "SHA-256");
export async function setupContext(request: Request, id: string | number) {
// remove retry attempt params from URL
const requestURL = new URL(request.url);

requestURL.searchParams.delete("attempt");
requestURL.searchParams.delete("requestID");

const contextID = requestURL.toString() + id;

key = await hash(contextID, "SHA-256");

const storedContext = await (env.WORKER_CONTEXTS as KVNamespace).get(key);

Expand Down
4 changes: 1 addition & 3 deletions src/workers/dilmahtea-me-dimass-webhook/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ async function handlePOST(request: Request, env: ENV): Promise<Response> {

const webhookData = JSON.parse(payload) as WebhookResponseData;

const contextID = request.url + webhookData.id;

await setupContext(contextID);
await setupContext(request, webhookData.id);

const event = request.headers.get("X-SP-Event") as AcceptedShipmentEvents;

Expand Down
2 changes: 1 addition & 1 deletion src/workers/dilmahtea-me-dimass-webhook/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ routes = [
kv_namespaces = [
{ binding = "EXACT_TOKENS", id = "0cbeb7b84a6a4e31b9c3360f97c9cef5" },
{ binding = "EXACT_LAYOUTS", id = "b75eb1bee9d7488fa33b8be89caab307" },
{ binding = "WORKER_CONTEXTS", id = "3fcd1790b1e644caa0d76d1be2fc27f7" }
{ binding = "WORKER_CONTEXTS", id = "bf39422efbc34bd58d3c3e064660474f" }
]
services = [{ binding = "RETRY_WORKERS", service = "dilmahtea-me-retry-workers" }]

Expand Down
4 changes: 1 addition & 3 deletions src/workers/dilmahtea-me-stripe-webhook/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ async function handlePOST(request: Request, env: ENV) {
// @ts-ignore
const { paymentID, payment_type } = event.data.object.metadata as MetaData;

const contextID = request.url + paymentID;

await setupContext(contextID);
await setupContext(request, paymentID);

const PAYMENT_INTENTS =
payment_type === "crowdfunding"
Expand Down
2 changes: 1 addition & 1 deletion src/workers/dilmahtea-me-stripe-webhook/wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ kv_namespaces = [
{ binding = "EXACT_TOKENS", id = "0cbeb7b84a6a4e31b9c3360f97c9cef5" },
{ binding = "CROWDFUNDINGS", id = "c971dd86589647799fb64dde47563fac" },
{ binding = "ECOMMERCE_PAYMENTS", id = "5086c43e26a14fa3a177ea876f514a8f" },
{ binding = "WORKER_CONTEXTS", id = "3fcd1790b1e644caa0d76d1be2fc27f7" }
{ binding = "WORKER_CONTEXTS", id = "bf39422efbc34bd58d3c3e064660474f" }
]
services = [{ binding = "RETRY_WORKERS", service = "dilmahtea-me-retry-workers" }]

Expand Down

0 comments on commit ee46a20

Please sign in to comment.