Skip to content

Commit 868ba40

Browse files
committed
CompleteAttemptStatus COMPLETED_SUCCESSFULLY
1 parent e086ef9 commit 868ba40

File tree

1 file changed

+19
-41
lines changed

1 file changed

+19
-41
lines changed

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

Lines changed: 19 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
flattenAttributes,
99
sanitizeError,
1010
} from "@trigger.dev/core/v3";
11-
import { PrismaClientOrTransaction } from "~/db.server";
11+
import { $transaction, PrismaClientOrTransaction } from "~/db.server";
1212
import { AuthenticatedEnvironment } from "~/services/apiAuth.server";
1313
import { logger } from "~/services/logger.server";
1414
import { safeJsonParse } from "~/utils/json";
@@ -111,49 +111,27 @@ export class CompleteAttemptService extends BaseService {
111111
taskRunAttempt: NonNullable<FoundAttempt>,
112112
env?: AuthenticatedEnvironment
113113
): Promise<"COMPLETED"> {
114-
/*
115-
"COMPLETED"
116-
117-
Steps:
118-
1. Updates the run *attempt* to completed AND the run to completed successfully
119-
2. marqs ack
120-
3. Complete the run span OTEL event
121-
4. Resume the task dependencies
122-
123-
Inputs:
124-
- taskRunAttempt: id
125-
- taskRun: id, spanId
126-
- output
127-
- outputType
128-
- usage
129-
- Prisma client/transaction
130-
131-
Questions:
132-
- Why do we ack after the db update?
133-
*/
114+
const finalizeService = new FinalizeTaskRunService();
134115

135-
await this._prisma.taskRunAttempt.update({
136-
where: { id: taskRunAttempt.id },
137-
data: {
138-
status: "COMPLETED",
139-
completedAt: new Date(),
140-
output: completion.output,
141-
outputType: completion.outputType,
142-
usageDurationMs: completion.usage?.durationMs,
143-
taskRun: {
144-
update: {
145-
data: {
146-
status: "COMPLETED_SUCCESSFULLY",
147-
completedAt: new Date(),
148-
},
149-
},
116+
await $transaction(this._prisma, async (tx) => {
117+
await tx.taskRunAttempt.update({
118+
where: { id: taskRunAttempt.id },
119+
data: {
120+
status: "COMPLETED",
121+
completedAt: new Date(),
122+
output: completion.output,
123+
outputType: completion.outputType,
124+
usageDurationMs: completion.usage?.durationMs,
150125
},
151-
},
152-
});
153-
154-
logger.debug("Completed attempt successfully, ACKing message");
126+
});
155127

156-
await marqs?.acknowledgeMessage(taskRunAttempt.taskRunId);
128+
await finalizeService.call({
129+
tx,
130+
id: taskRunAttempt.taskRun.id,
131+
status: "COMPLETED_SUCCESSFULLY",
132+
completedAt: new Date(),
133+
});
134+
});
157135

158136
// Now we need to "complete" the task run event/span
159137
await eventRepository.completeEvent(taskRunAttempt.taskRun.spanId, {

0 commit comments

Comments
 (0)