Skip to content

Commit 73cb766

Browse files
committed
Fixing the create tags in the new run engine trigger task service
1 parent ea8e9dc commit 73cb766

File tree

4 files changed

+77
-609
lines changed

4 files changed

+77
-609
lines changed

apps/webapp/app/models/taskRunTag.server.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { prisma } from "~/db.server";
22
import { generateFriendlyId } from "~/v3/friendlyIdentifiers";
3+
import { PrismaClientOrTransaction } from "@trigger.dev/database";
34

45
export const MAX_TAGS_PER_RUN = 10;
56

6-
export async function createTag({ tag, projectId }: { tag: string; projectId: string }) {
7+
export async function createTag(
8+
{ tag, projectId }: { tag: string; projectId: string },
9+
prismaClient: PrismaClientOrTransaction = prisma
10+
) {
711
if (tag.trim().length === 0) return;
8-
return prisma.taskRunTag.upsert({
12+
return prismaClient.taskRunTag.upsert({
913
where: {
1014
projectId_name: {
1115
projectId: projectId,
@@ -21,6 +25,48 @@ export async function createTag({ tag, projectId }: { tag: string; projectId: st
2125
});
2226
}
2327

28+
export type TagRecord = {
29+
id: string;
30+
name: string;
31+
};
32+
33+
export async function createTags(
34+
{
35+
tags,
36+
projectId,
37+
}: {
38+
tags: string | string[] | undefined;
39+
projectId: string;
40+
},
41+
prismaClient: PrismaClientOrTransaction = prisma
42+
): Promise<TagRecord[]> {
43+
if (!tags) {
44+
return [];
45+
}
46+
47+
const tagsArray = typeof tags === "string" ? [tags] : tags;
48+
49+
if (tagsArray.length === 0) {
50+
return [];
51+
}
52+
53+
const tagRecords: TagRecord[] = [];
54+
for (const tag of tagsArray) {
55+
const tagRecord = await createTag(
56+
{
57+
tag,
58+
projectId,
59+
},
60+
prismaClient
61+
);
62+
if (tagRecord) {
63+
tagRecords.push({ id: tagRecord.id, name: tagRecord.name });
64+
}
65+
}
66+
67+
return tagRecords;
68+
}
69+
2470
export async function getTagsForRunId({
2571
friendlyId,
2672
environmentId,

apps/webapp/app/runEngine/services/triggerTask.server.ts

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -298,20 +298,13 @@ export class RunEngineTriggerTaskService extends WithRunEngine {
298298
span.setAttribute("queueName", queueName);
299299

300300
//upsert tags
301-
let tags: { id: string; name: string }[] = [];
302-
const bodyTags =
303-
typeof body.options?.tags === "string" ? [body.options.tags] : body.options?.tags;
304-
305-
if (bodyTags && bodyTags.length > 0) {
306-
const tagRecords = await createTags(
307-
{
308-
tags: bodyTags,
309-
projectId: environment.projectId,
310-
},
311-
this._prisma
312-
);
313-
tags = tagRecords.filter(Boolean).map((tr) => ({ id: tr.id, name: tr.name }));
314-
}
301+
const tags = await createTags(
302+
{
303+
tags: body.options?.tags,
304+
projectId: environment.projectId,
305+
},
306+
this._prisma
307+
);
315308

316309
const depth = parentRun ? parentRun.depth + 1 : 0;
317310

0 commit comments

Comments
 (0)