Skip to content

Commit 28beafd

Browse files
committed
Allow passing in an include when finalizing the run
1 parent ed6e364 commit 28beafd

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed
Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,47 @@
1+
import { TaskRun, type Prisma, type TaskRunStatus } from "@trigger.dev/database";
2+
import { type PrismaClientOrTransaction } from "~/db.server";
13
import { marqs } from "~/v3/marqs/index.server";
24
import { BaseService } from "./baseService.server";
3-
import { type TaskRunStatus } from "@trigger.dev/database";
4-
import { type PrismaClientOrTransaction } from "~/db.server";
55

6-
type Input = {
6+
type BaseInput = {
77
tx: PrismaClientOrTransaction;
88
id: string;
99
status: TaskRunStatus;
1010
expiredAt?: Date;
1111
completedAt?: Date;
1212
};
1313

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;
1925

2026
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+
> {
2237
await marqs?.acknowledgeMessage(id);
2338

2439
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 } : {}),
3343
});
3444

35-
return run;
45+
return run as Output<T>;
3646
}
3747
}

0 commit comments

Comments
 (0)