-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathcancelTaskRun.server.ts
More file actions
54 lines (48 loc) · 1.55 KB
/
cancelTaskRun.server.ts
File metadata and controls
54 lines (48 loc) · 1.55 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
import { RunEngineVersion, type TaskRun } from "@trigger.dev/database";
import { logger } from "~/services/logger.server";
import { eventRepository } from "../eventRepository.server";
import { engine } from "../runEngine.server";
import { getTaskEventStoreTableForRun } from "../taskEventStore.server";
import { BaseService } from "./baseService.server";
import { CancelTaskRunServiceV1 } from "./cancelTaskRunV1.server";
export type CancelTaskRunServiceOptions = {
reason?: string;
cancelAttempts?: boolean;
cancelledAt?: Date;
};
type CancelTaskRunServiceResult = {
id: string;
};
export class CancelTaskRunService extends BaseService {
public async call(
taskRun: TaskRun,
options?: CancelTaskRunServiceOptions
): Promise<CancelTaskRunServiceResult | undefined> {
if (taskRun.engine === RunEngineVersion.V1) {
return await this.callV1(taskRun, options);
} else {
return await this.callV2(taskRun, options);
}
}
private async callV1(
taskRun: TaskRun,
options?: CancelTaskRunServiceOptions
): Promise<CancelTaskRunServiceResult | undefined> {
const service = new CancelTaskRunServiceV1(this._prisma);
return await service.call(taskRun, options);
}
private async callV2(
taskRun: TaskRun,
options?: CancelTaskRunServiceOptions
): Promise<CancelTaskRunServiceResult | undefined> {
const result = await engine.cancelRun({
runId: taskRun.id,
completedAt: options?.cancelledAt,
reason: options?.reason,
tx: this._prisma,
});
return {
id: result.run.id,
};
}
}