-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathresources.$projectId.deployments.$deploymentShortCode.retry-indexing.ts
More file actions
108 lines (95 loc) · 2.94 KB
/
resources.$projectId.deployments.$deploymentShortCode.retry-indexing.ts
File metadata and controls
108 lines (95 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
import { parse } from "@conform-to/zod";
import { ActionFunction, json } from "@remix-run/node";
import { z } from "zod";
import { prisma } from "~/db.server";
import { redirectWithErrorMessage, redirectWithSuccessMessage } from "~/models/message.server";
import { logger } from "~/services/logger.server";
import { requireUserId } from "~/services/session.server";
import { deploymentIndexingIsRetryable } from "~/v3/deploymentStatus";
import { RetryDeploymentIndexingService } from "~/v3/services/retryDeploymentIndexing.server";
export const rollbackSchema = z.object({
redirectUrl: z.string(),
});
const ParamSchema = z.object({
projectId: z.string(),
deploymentShortCode: z.string(),
});
export const action: ActionFunction = async ({ request, params }) => {
const userId = await requireUserId(request);
const { projectId, deploymentShortCode } = ParamSchema.parse(params);
console.log("projectId", projectId);
console.log("deploymentShortCode", deploymentShortCode);
const formData = await request.formData();
const submission = parse(formData, { schema: rollbackSchema });
if (!submission.value) {
return json(submission);
}
try {
const project = await prisma.project.findUnique({
where: {
id: projectId,
organization: {
members: {
some: {
userId,
},
},
},
},
});
if (!project) {
return redirectWithErrorMessage(submission.value.redirectUrl, request, "Project not found");
}
const deployment = await prisma.workerDeployment.findUnique({
where: {
projectId_shortCode: {
projectId: project.id,
shortCode: deploymentShortCode,
},
},
});
if (!deployment) {
return redirectWithErrorMessage(
submission.value.redirectUrl,
request,
"Deployment not found"
);
}
if (!deploymentIndexingIsRetryable(deployment)) {
return redirectWithErrorMessage(
submission.value.redirectUrl,
request,
"Deployment indexing not in retryable state"
);
}
const startIndexing = new RetryDeploymentIndexingService();
await startIndexing.call(deployment.id);
return redirectWithSuccessMessage(
submission.value.redirectUrl,
request,
"Retrying deployment indexing"
);
} catch (error) {
if (error instanceof Error) {
logger.error("Failed to retry deployment indexing", {
error: {
name: error.name,
message: error.message,
stack: error.stack,
},
projectId,
deploymentShortCode,
});
submission.error = { runParam: [error.message] };
return json(submission);
} else {
logger.error("Failed to retry deployment indexing", {
error,
projectId,
deploymentShortCode,
});
submission.error = { runParam: [JSON.stringify(error)] };
return json(submission);
}
}
};