Skip to content

Commit bd07781

Browse files
committed
fixed code rabbit review
1 parent 1e02704 commit bd07781

File tree

4 files changed

+20
-26
lines changed

4 files changed

+20
-26
lines changed

apps/webapp/app/routes/api.v1.idempotencyKeys.$key.reset.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ServiceValidationError } from "~/v3/services/baseService.server";
33
import { z } from "zod";
44
import { createActionApiRoute } from "~/services/routeBuilders/apiBuilder.server";
55
import { ResetIdempotencyKeyService } from "~/v3/services/resetIdempotencyKey.server";
6+
import { logger } from "~/services/logger.server";
67

78
const ParamsSchema = z.object({
89
key: z.string(),
@@ -39,6 +40,10 @@ export const { action } = createActionApiRoute(
3940
return json({ error: error.message }, { status: error.status ?? 400 });
4041
}
4142

43+
logger.error("Failed to reset idempotency key via API", {
44+
error: error instanceof Error ? { name: error.name, message: error.message, stack: error.stack } : String(error),
45+
});
46+
4247
return json({ error: "Internal Server Error" }, { status: 500 });
4348
}
4449

apps/webapp/app/routes/resources.orgs.$organizationSlug.projects.$projectParam.env.$envParam.runs.$runParam.idempotencyKey.reset.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { parse } from "@conform-to/zod";
22
import { type ActionFunction, json } from "@remix-run/node";
33
import { z } from "zod";
44
import { prisma } from "~/db.server";
5-
import { jsonWithErrorMessage, jsonWithSuccessMessage } from "~/models/message.server";
5+
import { jsonWithErrorMessage } from "~/models/message.server";
66
import { logger } from "~/services/logger.server";
77
import { requireUserId } from "~/services/session.server";
88
import { ResetIdempotencyKeyService } from "~/v3/services/resetIdempotencyKey.server";
@@ -100,11 +100,7 @@ export const action: ActionFunction = async ({ request, params }) => {
100100
organization: environment.project.organization,
101101
});
102102

103-
return jsonWithSuccessMessage(
104-
{ success: true },
105-
request,
106-
"Idempotency key reset successfully"
107-
);
103+
return json({ success: true });
108104
} catch (error) {
109105
if (error instanceof Error) {
110106
logger.error("Failed to reset idempotency key", {

apps/webapp/app/v3/services/resetIdempotencyKey.server.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,25 @@ export class ResetIdempotencyKeyService extends BaseService {
77
taskIdentifier: string,
88
authenticatedEnv: AuthenticatedEnvironment
99
): Promise<{ id: string }> {
10-
// Find all runs with this idempotency key and task identifier in the authenticated environment
11-
const runs = await this._prisma.taskRun.findMany({
10+
const { count } = await this._prisma.taskRun.updateMany({
1211
where: {
1312
idempotencyKey,
1413
taskIdentifier,
1514
runtimeEnvironmentId: authenticatedEnv.id,
1615
},
17-
select: {
18-
id: true,
16+
data: {
17+
idempotencyKey: null,
18+
idempotencyKeyExpiresAt: null,
1919
},
2020
});
2121

22-
if (runs.length === 0) {
22+
if (count === 0) {
2323
throw new ServiceValidationError(
2424
`No runs found with idempotency key: ${idempotencyKey} and task: ${taskIdentifier}`,
2525
404
2626
);
2727
}
2828

29-
// Update all runs to clear the idempotency key
30-
await this._prisma.taskRun.updateMany({
31-
where: {
32-
idempotencyKey,
33-
taskIdentifier,
34-
runtimeEnvironmentId: authenticatedEnv.id,
35-
},
36-
data: {
37-
idempotencyKey: null,
38-
idempotencyKeyExpiresAt: null,
39-
},
40-
});
41-
4229
return { id: idempotencyKey };
4330
}
4431
}

packages/core/src/v3/idempotencyKeys.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { apiClientManager } from "./apiClientManager-api.js";
22
import { taskContext } from "./task-context-api.js";
33
import { IdempotencyKey } from "./types/idempotencyKeys.js";
44
import { digestSHA256 } from "./utils/crypto.js";
5+
import type { ZodFetchOptions } from "./apiClient/core.js";
56

67
export function isIdempotencyKey(
78
value: string | string[] | IdempotencyKey
@@ -137,9 +138,14 @@ export function attemptKey(ctx: AttemptKeyMaterial): string {
137138
/** Resets an idempotency key, effectively deleting it from the associated task.*/
138139
export async function resetIdempotencyKey(
139140
taskIdentifier: string,
140-
idempotencyKey: string
141+
idempotencyKey: string,
142+
requestOptions?: ZodFetchOptions
141143
): Promise<{ id: string }> {
142144
const client = apiClientManager.clientOrThrow();
143145

144-
return client.resetIdempotencyKey(taskIdentifier, idempotencyKey);
146+
return client.resetIdempotencyKey(
147+
taskIdentifier,
148+
idempotencyKey,
149+
requestOptions
150+
);
145151
}

0 commit comments

Comments
 (0)