Skip to content

Commit ac58b84

Browse files
committed
CancelAttemptService using FinalizeTaskRunService
1 parent 366dbff commit ac58b84

File tree

1 file changed

+24
-43
lines changed

1 file changed

+24
-43
lines changed

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

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
import { AuthenticatedEnvironment } from "~/services/apiAuth.server";
1+
import { $transaction, type PrismaClientOrTransaction, prisma } from "~/db.server";
2+
import { type AuthenticatedEnvironment } from "~/services/apiAuth.server";
23
import { logger } from "~/services/logger.server";
3-
import { marqs } from "~/v3/marqs/index.server";
44
import { eventRepository } from "../eventRepository.server";
5-
import { BaseService } from "./baseService.server";
6-
7-
import { PrismaClientOrTransaction, prisma } from "~/db.server";
85
import { isCancellableRunStatus } from "../taskStatus";
6+
import { BaseService } from "./baseService.server";
7+
import { FinalizeTaskRunService } from "./finalizeTaskRun.server";
98
import { ResumeTaskRunDependenciesService } from "./resumeTaskRunDependencies.server";
109

1110
export class CancelAttemptService extends BaseService {
@@ -51,45 +50,27 @@ export class CancelAttemptService extends BaseService {
5150
return;
5251
}
5352

54-
/*
55-
"INTERRUPTED" (or leave it as is)
56-
57-
Steps:
58-
1. marqs ack
59-
2. Updates the run *attempt* to canceled AND potentially the run to INTERRUPTED
60-
3. Cancels all incomplete OTEL events
61-
4. Enqueues resuming task run dependencies
62-
63-
Inputs:
64-
- taskRun: id, status, friendlyId
65-
- taskRunAttempt: friendlyId
66-
- cancelledAt
67-
- reason
68-
- Prisma client/transaction
69-
*/
70-
71-
await marqs?.acknowledgeMessage(taskRunId);
72-
73-
await this._prisma.taskRunAttempt.update({
74-
where: {
75-
friendlyId: attemptId,
76-
},
77-
data: {
78-
status: "CANCELED",
79-
completedAt: cancelledAt,
80-
taskRun: {
81-
update: {
82-
data: {
83-
status: isCancellableRunStatus(taskRunAttempt.taskRun.status)
84-
? "INTERRUPTED"
85-
: undefined,
86-
completedAt: isCancellableRunStatus(taskRunAttempt.taskRun.status)
87-
? cancelledAt
88-
: undefined,
89-
},
90-
},
53+
const finalizeService = new FinalizeTaskRunService();
54+
55+
await $transaction(this._prisma, async (tx) => {
56+
await tx.taskRunAttempt.update({
57+
where: {
58+
friendlyId: attemptId,
9159
},
92-
},
60+
data: {
61+
status: "CANCELED",
62+
completedAt: cancelledAt,
63+
},
64+
});
65+
66+
await finalizeService.call({
67+
tx,
68+
id: taskRunId,
69+
status: isCancellableRunStatus(taskRunAttempt.taskRun.status) ? "INTERRUPTED" : undefined,
70+
completedAt: isCancellableRunStatus(taskRunAttempt.taskRun.status)
71+
? cancelledAt
72+
: undefined,
73+
});
9374
});
9475

9576
const inProgressEvents = await eventRepository.queryIncompleteEvents({

0 commit comments

Comments
 (0)