-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathApiWaitpointPresenter.server.ts
More file actions
81 lines (77 loc) · 2.61 KB
/
ApiWaitpointPresenter.server.ts
File metadata and controls
81 lines (77 loc) · 2.61 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
import { logger, type RuntimeEnvironmentType } from "@trigger.dev/core/v3";
import { type RunEngineVersion } from "@trigger.dev/database";
import { ServiceValidationError } from "~/v3/services/baseService.server";
import { BasePresenter } from "./basePresenter.server";
import { WaitpointPresenter } from "./WaitpointPresenter.server";
import { waitpointStatusToApiStatus } from "./WaitpointListPresenter.server";
export class ApiWaitpointPresenter extends BasePresenter {
public async call(
environment: {
id: string;
type: RuntimeEnvironmentType;
project: {
id: string;
engine: RunEngineVersion;
};
},
waitpointId: string
) {
return this.trace("call", async (span) => {
const waitpoint = await this._replica.waitpoint.findFirst({
where: {
id: waitpointId,
environmentId: environment.id,
},
select: {
friendlyId: true,
type: true,
status: true,
idempotencyKey: true,
userProvidedIdempotencyKey: true,
idempotencyKeyExpiresAt: true,
inactiveIdempotencyKey: true,
output: true,
outputType: true,
outputIsError: true,
completedAfter: true,
completedAt: true,
createdAt: true,
connectedRuns: {
select: {
friendlyId: true,
},
take: 5,
},
tags: true,
},
});
if (!waitpoint) {
logger.error(`WaitpointPresenter: Waitpoint not found`, {
id: waitpointId,
});
throw new ServiceValidationError("Waitpoint not found");
}
let isTimeout = false;
if (waitpoint.outputIsError && waitpoint.output) {
isTimeout = true;
}
return {
id: waitpoint.friendlyId,
type: waitpoint.type,
status: waitpointStatusToApiStatus(waitpoint.status, waitpoint.outputIsError),
idempotencyKey: waitpoint.idempotencyKey,
userProvidedIdempotencyKey: waitpoint.userProvidedIdempotencyKey,
idempotencyKeyExpiresAt: waitpoint.idempotencyKeyExpiresAt ?? undefined,
inactiveIdempotencyKey: waitpoint.inactiveIdempotencyKey ?? undefined,
output: waitpoint.output ?? undefined,
outputType: waitpoint.outputType,
outputIsError: waitpoint.outputIsError,
timeoutAt: waitpoint.completedAfter ?? undefined,
completedAfter: waitpoint.completedAfter ?? undefined,
completedAt: waitpoint.completedAt ?? undefined,
createdAt: waitpoint.createdAt,
tags: waitpoint.tags,
};
});
}
}