Skip to content

Commit ab39f5a

Browse files
committed
CancelTaskRunService using FinalizeTaskRunService
1 parent ccea150 commit ab39f5a

File tree

1 file changed

+9
-31
lines changed

1 file changed

+9
-31
lines changed

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

Lines changed: 9 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { Prisma, TaskRun } from "@trigger.dev/database";
1+
import { type Prisma, type TaskRun } from "@trigger.dev/database";
22
import assertNever from "assert-never";
33
import { logger } from "~/services/logger.server";
4-
import { marqs } from "~/v3/marqs/index.server";
54
import { eventRepository } from "../eventRepository.server";
65
import { socketIo } from "../handleSocketIo.server";
76
import { devPubSub } from "../marqs/devPubSub.server";
7+
import { CANCELLABLE_ATTEMPT_STATUSES, isCancellableRunStatus } from "../taskStatus";
88
import { BaseService } from "./baseService.server";
99
import { CancelAttemptService } from "./cancelAttempt.server";
10-
import { CANCELLABLE_ATTEMPT_STATUSES, isCancellableRunStatus } from "../taskStatus";
1110
import { CancelTaskAttemptDependenciesService } from "./cancelTaskAttemptDependencies.server";
11+
import { FinalizeTaskRunService } from "./finalizeTaskRun.server";
1212

1313
type ExtendedTaskRun = Prisma.TaskRunGetPayload<{
1414
include: {
@@ -47,34 +47,12 @@ export class CancelTaskRunService extends BaseService {
4747
return;
4848
}
4949

50-
/*
51-
"CANCELED"
52-
53-
Steps:
54-
1. marqs ack
55-
2. Updates the run to canceled and gets attempts, dependencies, etc
56-
3. Cancels all incomplete OTEL events
57-
4. Cancels all in progress attempts
58-
5. Cancels all in progress workers
59-
60-
Inputs:
61-
- taskRun: id, friendlyId
62-
- cancelledAt
63-
- reason
64-
*/
65-
66-
// Remove the task run from the queue if it's there for some reason
67-
await marqs?.acknowledgeMessage(taskRun.id);
68-
69-
// Set the task run status to cancelled
70-
const cancelledTaskRun = await this._prisma.taskRun.update({
71-
where: {
72-
id: taskRun.id,
73-
},
74-
data: {
75-
status: "CANCELED",
76-
completedAt: opts.cancelledAt,
77-
},
50+
const finalizeService = new FinalizeTaskRunService();
51+
const cancelledTaskRun = await finalizeService.call({
52+
tx: this._prisma,
53+
id: taskRun.id,
54+
status: "CANCELED",
55+
completedAt: opts.cancelledAt,
7856
include: {
7957
attempts: {
8058
where: {

0 commit comments

Comments
 (0)