Skip to content

Commit ff45860

Browse files
committed
Merge branch 'main' into linear-getall-types
2 parents 1f9cb10 + 3ca4456 commit ff45860

File tree

10 files changed

+142
-139
lines changed

10 files changed

+142
-139
lines changed

apps/webapp/app/components/navigation/ProjectSideMenu.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ export function ProjectSideMenu() {
119119
data-action="onboarding"
120120
/>
121121
<SideMenuItem
122-
name="Homepage"
123-
icon="external-link"
124-
to="https://trigger.dev"
122+
name="Changelog"
123+
icon="list"
124+
to="https://trigger.dev/changelog"
125125
isCollapsed={isCollapsed}
126-
data-action="onboarding"
126+
data-action="changelog"
127127
target="_blank"
128128
/>
129129
<SideMenuItem

apps/webapp/app/components/primitives/NamedIcon.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ const icons = {
131131
"clipboard-checked": (className: string) => (
132132
<ClipboardDocumentCheckIcon className={cn("text-dimmed", className)} />
133133
),
134+
list: (className: string) => <ListBulletIcon className={cn("text-slate-400", className)} />,
134135
log: (className: string) => (
135136
<ChatBubbleLeftEllipsisIcon className={cn("text-slate-400", className)} />
136137
),

apps/webapp/app/db.server.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export type PrismaTransactionOptions = {
3131
/** Sets the transaction isolation level. By default this is set to the value currently configured in your database. */
3232
isolationLevel?: Prisma.TransactionIsolationLevel;
3333

34-
rethrowPrismaErrors?: boolean;
34+
swallowPrismaErrors?: boolean;
3535
};
3636

3737
export async function $transaction<R>(
@@ -55,11 +55,9 @@ export async function $transaction<R>(
5555
name: error.name,
5656
});
5757

58-
if (options?.rethrowPrismaErrors) {
59-
throw error;
58+
if (options?.swallowPrismaErrors) {
59+
return;
6060
}
61-
62-
return;
6361
}
6462

6563
throw error;
@@ -124,6 +122,10 @@ function getClient() {
124122
emit: "stdout",
125123
level: "warn",
126124
},
125+
// {
126+
// emit: "stdout",
127+
// level: "query",
128+
// },
127129
],
128130
});
129131

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam._index/route.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ function ExampleJobs() {
160160
height="250"
161161
allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share"
162162
allowFullScreen
163-
className="mb-4 w-full border-b border-slate-800"
163+
className="mb-4 border-b border-slate-800"
164164
/>
165165
<Header2 spacing>How to create a Job</Header2>
166166
<Paragraph variant="small" spacing>

apps/webapp/app/routes/api.v1.runs.$runId.tasks.$id.complete.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { json } from "@remix-run/server-runtime";
33
import type { CompleteTaskBodyOutput, ServerTask } from "@trigger.dev/core";
44
import { CompleteTaskBodyInputSchema } from "@trigger.dev/core";
55
import { z } from "zod";
6-
import { $transaction, PrismaClient, prisma } from "~/db.server";
6+
import { PrismaClient, prisma } from "~/db.server";
77
import { taskWithAttemptsToServerTask } from "~/models/task.server";
88
import type { AuthenticatedEnvironment } from "~/services/apiAuth.server";
99
import { authenticateApiRequest } from "~/services/apiAuth.server";
@@ -86,8 +86,8 @@ export class CompleteRunTaskService {
8686
): Promise<ServerTask | undefined> {
8787
// Using a transaction, we'll first check to see if the task already exists and return if if it does
8888
// If it doesn't exist, we'll create it and return it
89-
const task = await this.#prismaClient.$transaction(async (prisma) => {
90-
const existingTask = await prisma.task.findUnique({
89+
const task = await this.#prismaClient.$transaction(async (tx) => {
90+
const existingTask = await tx.task.findUnique({
9191
where: {
9292
id,
9393
},
@@ -129,35 +129,31 @@ export class CompleteRunTaskService {
129129
return existingTask;
130130
}
131131

132-
const task = await $transaction(prisma, async (tx) => {
133-
if (existingTask.attempts.length === 1) {
134-
await tx.taskAttempt.update({
135-
where: {
136-
id: existingTask.attempts[0].id,
137-
},
138-
data: {
139-
status: "COMPLETED",
140-
},
141-
});
142-
}
143-
144-
return await tx.task.update({
132+
if (existingTask.attempts.length === 1) {
133+
await tx.taskAttempt.update({
145134
where: {
146-
id,
135+
id: existingTask.attempts[0].id,
147136
},
148137
data: {
149138
status: "COMPLETED",
150-
output: taskBody.output ?? undefined,
151-
completedAt: new Date(),
152-
outputProperties: taskBody.properties,
153-
},
154-
include: {
155-
attempts: true,
156139
},
157140
});
158-
});
141+
}
159142

160-
return task;
143+
return await tx.task.update({
144+
where: {
145+
id,
146+
},
147+
data: {
148+
status: "COMPLETED",
149+
output: taskBody.output ?? undefined,
150+
completedAt: new Date(),
151+
outputProperties: taskBody.properties,
152+
},
153+
include: {
154+
attempts: true,
155+
},
156+
});
161157
});
162158

163159
return task ? taskWithAttemptsToServerTask(task) : undefined;

apps/webapp/app/routes/api.v1.runs.$runId.tasks.$id.fail.ts

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { ActionArgs } from "@remix-run/server-runtime";
22
import { json } from "@remix-run/server-runtime";
33
import { FailTaskBodyInput, FailTaskBodyInputSchema, ServerTask } from "@trigger.dev/core";
44
import { z } from "zod";
5-
import { $transaction, PrismaClient, prisma } from "~/db.server";
5+
import { PrismaClient, prisma } from "~/db.server";
66
import { taskWithAttemptsToServerTask } from "~/models/task.server";
77
import type { AuthenticatedEnvironment } from "~/services/apiAuth.server";
88
import { authenticateApiRequest } from "~/services/apiAuth.server";
@@ -86,8 +86,8 @@ export class FailRunTaskService {
8686
): Promise<ServerTask | undefined> {
8787
// Using a transaction, we'll first check to see if the task already exists and return if if it does
8888
// If it doesn't exist, we'll create it and return it
89-
const task = await this.#prismaClient.$transaction(async (prisma) => {
90-
const existingTask = await prisma.task.findUnique({
89+
const task = await this.#prismaClient.$transaction(async (tx) => {
90+
const existingTask = await tx.task.findUnique({
9191
where: {
9292
id,
9393
},
@@ -129,35 +129,31 @@ export class FailRunTaskService {
129129
return existingTask;
130130
}
131131

132-
const task = await $transaction(prisma, async (tx) => {
133-
if (existingTask.attempts.length === 1) {
134-
await tx.taskAttempt.update({
135-
where: {
136-
id: existingTask.attempts[0].id,
137-
},
138-
data: {
139-
status: "ERRORED",
140-
error: formatError(taskBody.error),
141-
},
142-
});
143-
}
144-
145-
return await prisma.task.update({
132+
if (existingTask.attempts.length === 1) {
133+
await tx.taskAttempt.update({
146134
where: {
147-
id,
135+
id: existingTask.attempts[0].id,
148136
},
149137
data: {
150138
status: "ERRORED",
151-
output: taskBody.error ?? undefined,
152-
completedAt: new Date(),
153-
},
154-
include: {
155-
attempts: true,
139+
error: formatError(taskBody.error),
156140
},
157141
});
158-
});
142+
}
159143

160-
return task;
144+
return await tx.task.update({
145+
where: {
146+
id,
147+
},
148+
data: {
149+
status: "ERRORED",
150+
output: taskBody.error ?? undefined,
151+
completedAt: new Date(),
152+
},
153+
include: {
154+
attempts: true,
155+
},
156+
});
161157
});
162158

163159
return task ? taskWithAttemptsToServerTask(task) : undefined;

apps/webapp/app/services/events/ingestSendEvent.server.ts

Lines changed: 42 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -34,77 +34,55 @@ export class IngestSendEvent {
3434
try {
3535
const deliverAt = this.#calculateDeliverAt(options);
3636

37-
return await $transaction(
38-
this.#prismaClient,
39-
async (tx) => {
40-
const externalAccount = options?.accountId
41-
? await tx.externalAccount.upsert({
42-
where: {
43-
environmentId_identifier: {
44-
environmentId: environment.id,
45-
identifier: options.accountId,
46-
},
47-
},
48-
create: {
37+
return await $transaction(this.#prismaClient, async (tx) => {
38+
const externalAccount = options?.accountId
39+
? await tx.externalAccount.upsert({
40+
where: {
41+
environmentId_identifier: {
4942
environmentId: environment.id,
50-
organizationId: environment.organizationId,
5143
identifier: options.accountId,
5244
},
53-
update: {},
54-
})
55-
: undefined;
56-
57-
// Create a new event in the database
58-
const eventLog = await tx.eventRecord.create({
59-
data: {
60-
organization: {
61-
connect: {
62-
id: environment.organizationId,
63-
},
6445
},
65-
project: {
66-
connect: {
67-
id: environment.projectId,
68-
},
46+
create: {
47+
environmentId: environment.id,
48+
organizationId: environment.organizationId,
49+
identifier: options.accountId,
6950
},
70-
environment: {
71-
connect: {
72-
id: environment.id,
73-
},
74-
},
75-
eventId: event.id,
76-
name: event.name,
77-
timestamp: event.timestamp ?? new Date(),
78-
payload: event.payload ?? {},
79-
context: event.context ?? {},
80-
source: event.source ?? "trigger.dev",
81-
sourceContext,
82-
deliverAt: deliverAt,
83-
externalAccount: externalAccount
84-
? {
85-
connect: {
86-
id: externalAccount.id,
87-
},
88-
}
89-
: {},
90-
},
91-
});
51+
update: {},
52+
})
53+
: undefined;
9254

93-
if (this.deliverEvents) {
94-
// Produce a message to the event bus
95-
await workerQueue.enqueue(
96-
"deliverEvent",
97-
{
98-
id: eventLog.id,
99-
},
100-
{ runAt: eventLog.deliverAt, tx, jobKey: `event:${eventLog.id}` }
101-
);
102-
}
55+
// Create a new event in the database
56+
const eventLog = await tx.eventRecord.create({
57+
data: {
58+
organizationId: environment.organizationId,
59+
projectId: environment.projectId,
60+
environmentId: environment.id,
61+
eventId: event.id,
62+
name: event.name,
63+
timestamp: event.timestamp ?? new Date(),
64+
payload: event.payload ?? {},
65+
context: event.context ?? {},
66+
source: event.source ?? "trigger.dev",
67+
sourceContext,
68+
deliverAt: deliverAt,
69+
externalAccountId: externalAccount ? externalAccount.id : undefined,
70+
},
71+
});
72+
73+
if (this.deliverEvents) {
74+
// Produce a message to the event bus
75+
await workerQueue.enqueue(
76+
"deliverEvent",
77+
{
78+
id: eventLog.id,
79+
},
80+
{ runAt: eventLog.deliverAt, tx, jobKey: `event:${eventLog.id}` }
81+
);
82+
}
10383

104-
return eventLog;
105-
},
106-
{ rethrowPrismaErrors: true }
107-
);
84+
return eventLog;
85+
});
10886
} catch (error) {
10987
const prismaError = PrismaErrorSchema.safeParse(error);
11088

apps/webapp/app/services/runs/createRun.server.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,29 +42,32 @@ export class CreateRunService {
4242

4343
return await $transaction(this.#prismaClient, async (tx) => {
4444
// Get the current max number for the given jobId
45-
const currentMaxNumber = await tx.jobRun.aggregate({
45+
const latestJob = await tx.jobRun.findFirst({
4646
where: { jobId: job.id },
47-
_max: { number: true },
47+
orderBy: { id: "desc" },
48+
select: {
49+
number: true,
50+
},
4851
});
4952

5053
// Increment the number for the new execution
51-
const newNumber = (currentMaxNumber._max.number ?? 0) + 1;
54+
const newNumber = (latestJob?.number ?? 0) + 1;
5255

5356
// Create the new execution with the incremented number
5457
const run = await tx.jobRun.create({
5558
data: {
5659
number: newNumber,
5760
preprocess: version.preprocessRuns,
58-
job: { connect: { id: job.id } },
59-
version: { connect: { id: version.id } },
60-
event: { connect: { id: eventId } },
61-
environment: { connect: { id: environment.id } },
62-
organization: { connect: { id: environment.organizationId } },
63-
project: { connect: { id: environment.projectId } },
64-
endpoint: { connect: { id: endpoint.id } },
65-
queue: { connect: { id: jobQueue.id } },
66-
externalAccount: eventRecord.externalAccountId
67-
? { connect: { id: eventRecord.externalAccountId } }
61+
jobId: job.id,
62+
versionId: version.id,
63+
eventId: eventId,
64+
environmentId: environment.id,
65+
organizationId: environment.organizationId,
66+
projectId: environment.projectId,
67+
endpointId: endpoint.id,
68+
queueId: jobQueue.id,
69+
externalAccountId: eventRecord.externalAccountId
70+
? eventRecord.externalAccountId
6871
: undefined,
6972
isTest: eventRecord.isTest,
7073
},

apps/webapp/app/services/worker.server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ function getWorkerQueue() {
161161
tasks: {
162162
"events.invokeDispatcher": {
163163
priority: 0, // smaller number = higher priority
164-
maxAttempts: 3,
164+
maxAttempts: 6,
165+
queueName: (payload) => `dispatcher:${payload.id}`, // use a queue for a dispatcher so runs are created sequentially
165166
handler: async (payload, job) => {
166167
const service = new InvokeDispatcherService();
167168

0 commit comments

Comments
 (0)