|
| 1 | +import { TaskRun, type Prisma, type TaskRunStatus } from "@trigger.dev/database"; |
| 2 | +import { type PrismaClientOrTransaction } from "~/db.server"; |
1 | 3 | import { marqs } from "~/v3/marqs/index.server";
|
2 | 4 | import { BaseService } from "./baseService.server";
|
3 |
| -import { type TaskRunStatus } from "@trigger.dev/database"; |
4 |
| -import { type PrismaClientOrTransaction } from "~/db.server"; |
5 | 5 |
|
6 |
| -type Input = { |
| 6 | +type BaseInput = { |
7 | 7 | tx: PrismaClientOrTransaction;
|
8 | 8 | id: string;
|
9 | 9 | status: TaskRunStatus;
|
10 | 10 | expiredAt?: Date;
|
11 | 11 | completedAt?: Date;
|
12 | 12 | };
|
13 | 13 |
|
14 |
| -//todo |
15 |
| -//1. ack |
16 |
| -//2. Using the passed in transaction client, update the run status and any optional dates passed in |
17 |
| -//3. Remove the run from it's concurrency sets in Redis |
18 |
| -//4? Do alerts if the run has failed |
| 14 | +type InputWithInclude<T extends Prisma.TaskRunInclude> = BaseInput & { |
| 15 | + include: T; |
| 16 | +}; |
| 17 | + |
| 18 | +type InputWithoutInclude = BaseInput & { |
| 19 | + include?: undefined; |
| 20 | +}; |
| 21 | + |
| 22 | +type Output<T extends Prisma.TaskRunInclude | undefined> = T extends Prisma.TaskRunInclude |
| 23 | + ? Prisma.TaskRunGetPayload<{ include: T }> |
| 24 | + : TaskRun; |
19 | 25 |
|
20 | 26 | export class FinalizeTaskRunService extends BaseService {
|
21 |
| - public async call({ tx, id, status, expiredAt, completedAt }: Input) { |
| 27 | + public async call<T extends Prisma.TaskRunInclude | undefined>({ |
| 28 | + tx, |
| 29 | + id, |
| 30 | + status, |
| 31 | + expiredAt, |
| 32 | + completedAt, |
| 33 | + include, |
| 34 | + }: T extends Prisma.TaskRunInclude ? InputWithInclude<T> : InputWithoutInclude): Promise< |
| 35 | + Output<T> |
| 36 | + > { |
22 | 37 | await marqs?.acknowledgeMessage(id);
|
23 | 38 |
|
24 | 39 | const run = await tx.taskRun.update({
|
25 |
| - where: { |
26 |
| - id, |
27 |
| - }, |
28 |
| - data: { |
29 |
| - status, |
30 |
| - expiredAt, |
31 |
| - completedAt, |
32 |
| - }, |
| 40 | + where: { id }, |
| 41 | + data: { status, expiredAt, completedAt }, |
| 42 | + ...(include ? { include } : {}), |
33 | 43 | });
|
34 | 44 |
|
35 |
| - return run; |
| 45 | + return run as Output<T>; |
36 | 46 | }
|
37 | 47 | }
|
0 commit comments