-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathadmin.api.v1.environments.$environmentId.ts
More file actions
101 lines (83 loc) · 2.68 KB
/
admin.api.v1.environments.$environmentId.ts
File metadata and controls
101 lines (83 loc) · 2.68 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
import { ActionFunctionArgs, json, LoaderFunctionArgs } from "@remix-run/server-runtime";
import { z } from "zod";
import { prisma } from "~/db.server";
import { requireAdminApiRequest } from "~/services/personalAccessToken.server";
import { engine } from "~/v3/runEngine.server";
import { updateEnvConcurrencyLimits } from "~/v3/runQueue.server";
const ParamsSchema = z.object({
environmentId: z.string(),
});
const RequestBodySchema = z.object({
envMaximumConcurrencyLimit: z.number(),
orgMaximumConcurrencyLimit: z.number(),
});
export async function action({ request, params }: ActionFunctionArgs) {
await requireAdminApiRequest(request);
const parsedParams = ParamsSchema.parse(params);
const rawBody = await request.json();
const body = RequestBodySchema.parse(rawBody);
const environment = await prisma.runtimeEnvironment.update({
where: {
id: parsedParams.environmentId,
},
data: {
maximumConcurrencyLimit: body.envMaximumConcurrencyLimit,
organization: {
update: {
data: {
maximumConcurrencyLimit: body.orgMaximumConcurrencyLimit,
},
},
},
},
include: {
organization: true,
project: true,
},
});
await updateEnvConcurrencyLimits(environment);
return json({ success: true });
}
const SearchParamsSchema = z.object({
queue: z.string().optional(),
});
export async function loader({ request, params }: LoaderFunctionArgs) {
await requireAdminApiRequest(request);
const parsedParams = ParamsSchema.parse(params);
const environment = await prisma.runtimeEnvironment.findFirst({
where: {
id: parsedParams.environmentId,
},
include: {
organization: true,
project: true,
},
});
if (!environment) {
return json({ error: "Environment not found" }, { status: 404 });
}
const requestUrl = new URL(request.url);
const searchParams = SearchParamsSchema.parse(
Object.fromEntries(requestUrl.searchParams.entries())
);
const concurrencyLimit = await engine.runQueue.getEnvConcurrencyLimit(environment);
const currentConcurrency = await engine.runQueue.currentConcurrencyOfEnvironment(environment);
if (searchParams.queue) {
const queueConcurrencyLimit = await engine.runQueue.getQueueConcurrencyLimit(
environment,
searchParams.queue
);
const queueCurrentConcurrency = await engine.runQueue.currentConcurrencyOfQueue(
environment,
searchParams.queue
);
return json({
id: environment.id,
concurrencyLimit,
currentConcurrency,
queueConcurrencyLimit,
queueCurrentConcurrency,
});
}
return json({ id: environment.id, concurrencyLimit, currentConcurrency });
}