-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathEnvironmentQueuePresenter.server.ts
More file actions
55 lines (48 loc) · 1.75 KB
/
EnvironmentQueuePresenter.server.ts
File metadata and controls
55 lines (48 loc) · 1.75 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
import { type AuthenticatedEnvironment } from "~/services/apiAuth.server";
import { marqs } from "~/v3/marqs/index.server";
import { engine } from "~/v3/runEngine.server";
import { getQueueSizeLimit } from "~/v3/utils/queueLimits.server";
import { BasePresenter } from "./basePresenter.server";
export type Environment = {
running: number;
queued: number;
concurrencyLimit: number;
burstFactor: number;
runsEnabled: boolean;
queueSizeLimit: number | null;
};
export class EnvironmentQueuePresenter extends BasePresenter {
async call(environment: AuthenticatedEnvironment): Promise<Environment> {
const [engineV1Executing, engineV2Executing, engineV1Queued, engineV2Queued] =
await Promise.all([
marqs.currentConcurrencyOfEnvironment(environment),
engine.concurrencyOfEnvQueue(environment),
marqs.lengthOfEnvQueue(environment),
engine.lengthOfEnvQueue(environment),
]);
const running = (engineV1Executing ?? 0) + (engineV2Executing ?? 0);
const queued = (engineV1Queued ?? 0) + (engineV2Queued ?? 0);
const organization = await this._replica.organization.findFirst({
where: {
id: environment.organizationId,
},
select: {
runsEnabled: true,
maximumDevQueueSize: true,
maximumDeployedQueueSize: true,
},
});
if (!organization) {
throw new Error("Organization not found");
}
const queueSizeLimit = getQueueSizeLimit(environment.type, organization);
return {
running,
queued,
concurrencyLimit: environment.maximumConcurrencyLimit,
burstFactor: environment.concurrencyLimitBurstFactor.toNumber(),
runsEnabled: environment.type === "DEVELOPMENT" || organization.runsEnabled,
queueSizeLimit,
};
}
}