Compare commits

...

3 Commits

Author SHA1 Message Date
Eric Allam 68d8c3e093 Another attempt at fixing createTag, this time doing retries in code on conflicts
🚀 Publish Trigger.dev Docker / units (push) Failing after 11m47s
🚀 Publish Trigger.dev Docker / typecheck (push) Failing after 11m47s
🚀 Publish Trigger.dev Docker / publish-webapp (push) Has been skipped
🚀 Publish Trigger.dev Docker / publish-worker (push) Has been skipped
2025-03-18 10:08:08 +00:00
Eric Allam 07ae80209a Fix getTagsForRunId after accidentally breaking it
🚀 Publish Trigger.dev Docker / units (push) Failing after 11m48s
🚀 Publish Trigger.dev Docker / typecheck (push) Failing after 12m45s
🚀 Publish Trigger.dev Docker / publish-webapp (push) Has been skipped
🚀 Publish Trigger.dev Docker / publish-worker (push) Has been skipped
2025-03-10 17:26:31 +00:00
Eric Allam 2769951a84 Ensure creating tags does not throw constraint validation error, fix batch v3 job retries
🚀 Publish Trigger.dev Docker / units (push) Failing after 12m45s
🚀 Publish Trigger.dev Docker / typecheck (push) Failing after 12m47s
🚀 Publish Trigger.dev Docker / publish-webapp (push) Has been skipped
🚀 Publish Trigger.dev Docker / publish-worker (push) Has been skipped
2025-03-10 17:15:42 +00:00
3 changed files with 36 additions and 15 deletions
+34 -14
View File
@@ -1,24 +1,44 @@
import { Prisma } from "@trigger.dev/database";
import { prisma } from "~/db.server";
import { generateFriendlyId } from "~/v3/friendlyIdentifiers";
export const MAX_TAGS_PER_RUN = 10;
const MAX_RETRIES = 3;
export async function createTag({ tag, projectId }: { tag: string; projectId: string }) {
if (tag.trim().length === 0) return;
return prisma.taskRunTag.upsert({
where: {
projectId_name: {
projectId: projectId,
name: tag,
},
},
create: {
name: tag,
friendlyId: generateFriendlyId("runtag"),
projectId: projectId,
},
update: {},
});
let attempts = 0;
const friendlyId = generateFriendlyId("runtag");
while (attempts < MAX_RETRIES) {
try {
return await prisma.taskRunTag.upsert({
where: {
projectId_name: {
projectId,
name: tag,
},
},
create: {
friendlyId,
name: tag,
projectId,
},
update: {},
});
} catch (error) {
if (error instanceof Prisma.PrismaClientKnownRequestError && error.code === "P2002") {
// Handle unique constraint violation (conflict)
attempts++;
if (attempts >= MAX_RETRIES) {
throw new Error(`Failed to create tag after ${MAX_RETRIES} attempts due to conflicts.`);
}
} else {
throw error; // Re-throw other errors
}
}
}
}
export async function getTagsForRunId({
@@ -682,7 +682,7 @@ export class BatchTriggerV3Service extends BaseService {
count:
options.strategy === "sequential"
? options.range.count
: options.range.count - result.workingIndex - options.range.start,
: options.range.count - (result.workingIndex - options.range.start),
},
attemptCount: $attemptCount,
strategy: options.strategy,
@@ -41,6 +41,7 @@ export const batchParentTask = task({
},
options: {
idempotencyKey: `item${i}`,
tags: ["foo:bar", "bar:baz"],
},
}));