Skip to content

Commit 5b9497d

Browse files
committed
Merge remote-tracking branch 'origin/main' into update-pricing-page-style
2 parents 93e68e4 + 73e7378 commit 5b9497d

File tree

154 files changed

+4188
-12934
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+4188
-12934
lines changed

.changeset/eleven-games-relate.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trigger.dev": patch
3+
---
4+
5+
add wait_for_run_to_complete tool so agents don't spam the get_run_details call after triggering

.cursor/rules/webapp.mdc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ alwaysApply: false
66

77
The main trigger.dev webapp, which powers it's API and dashboard and makes up the docker image that is produced as an OSS image, is a Remix 2.1.0 app that uses an express server, written in TypeScript. The following subsystems are either included in the webapp or are used by the webapp in another part of the monorepo:
88

9-
- `@trigger.dev/database` exports a Prisma 5.4.1 client that is used extensively in the webapp to access a PostgreSQL instance. The schema file is [schema.prisma](mdc:internal-packages/database/prisma/schema.prisma)
9+
- `@trigger.dev/database` exports a Prisma 6.14.0 client that is used extensively in the webapp to access a PostgreSQL instance. The schema file is [schema.prisma](mdc:internal-packages/database/prisma/schema.prisma)
1010
- `@trigger.dev/core` is a published package and is used to share code between the `@trigger.dev/sdk` and the webapp. It includes functionality but also a load of Zod schemas for data validation. When importing from `@trigger.dev/core` in the webapp, we never import the root `@trigger.dev/core` path, instead we favor one of the subpath exports that you can find in [package.json](mdc:packages/core/package.json)
1111
- `@internal/run-engine` has all the code needed to trigger a run and take it through it's lifecycle to completion.
1212
- `@trigger.dev/redis-worker` is a custom redis based background job/worker system that's used in the webapp and also used inside the run engine.
@@ -31,7 +31,10 @@ We originally the Trigger.dev "Run Engine" not as a single system, but just spre
3131
- The batch trigger API endpoint is [api.v1.tasks.batch.ts](mdc:apps/webapp/app/routes/api.v1.tasks.batch.ts)
3232
- Setup code for the prisma client is in [db.server.ts](mdc:apps/webapp/app/db.server.ts)
3333
- The run engine is configured in [runEngine.server.ts](mdc:apps/webapp/app/v3/runEngine.server.ts)
34-
- All the "services" that are found in app/v3/services/**/*.server.ts
34+
- All the "services" that are found in app/v3/services/\*_/_.server.ts
3535
- The code for the TaskEvent data, which is the otel data sent from tasks to our servers, is in both the [eventRepository.server.ts](mdc:apps/webapp/app/v3/eventRepository.server.ts) and also the [otlpExporter.server.ts](mdc:apps/webapp/app/v3/otlpExporter.server.ts). The otel endpoints which are hit from production and development otel exporters is [otel.v1.logs.ts](mdc:apps/webapp/app/routes/otel.v1.logs.ts) and [otel.v1.traces.ts](mdc:apps/webapp/app/routes/otel.v1.traces.ts)
36-
- We use "presenters" to move more complex loader code into a class, and you can find those are app/v3/presenters/**/*.server.ts
36+
- We use "presenters" to move more complex loader code into a class, and you can find those are app/v3/presenters/\*_/_.server.ts
3737

38+
- All the "services" that are found in app/v3/services/\*_/_.server.ts
39+
- The code for the TaskEvent data, which is the otel data sent from tasks to our servers, is in both the [eventRepository.server.ts](mdc:apps/webapp/app/v3/eventRepository.server.ts) and also the [otlpExporter.server.ts](mdc:apps/webapp/app/v3/otlpExporter.server.ts). The otel endpoints which are hit from production and development otel exporters is [otel.v1.logs.ts](mdc:apps/webapp/app/routes/otel.v1.logs.ts) and [otel.v1.traces.ts](mdc:apps/webapp/app/routes/otel.v1.traces.ts)
40+
- We use "presenters" to move more complex loader code into a class, and you can find those are app/v3/presenters/\*_/_.server.ts

.dockerignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
**/dist
1717
**/node_modules
1818

19+
**/generated/prisma
20+
1921
apps/webapp/build
2022
apps/webapp/public/build
2123

.github/workflows/unit-tests-webapp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ jobs:
8585
DIRECT_URL: postgresql://postgres:postgres@localhost:5432/postgres
8686
SESSION_SECRET: "secret"
8787
MAGIC_LINK_SECRET: "secret"
88-
ENCRYPTION_KEY: "secret"
88+
ENCRYPTION_KEY: "dummy-encryption-keeeey-32-bytes"
8989
DEPLOY_REGISTRY_HOST: "docker.io"
9090
CLICKHOUSE_URL: "http://default:password@localhost:8123"
9191

.vscode/launch.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"request": "launch",
6060
"name": "Debug V3 Dev CLI",
6161
"command": "pnpm exec trigger dev",
62-
"cwd": "${workspaceFolder}/references/v3-catalog",
62+
"cwd": "${workspaceFolder}/references/hello-world",
6363
"sourceMaps": true
6464
},
6565
{
@@ -83,31 +83,31 @@
8383
"request": "launch",
8484
"name": "Debug V3 Deploy CLI",
8585
"command": "pnpm exec trigger deploy --self-hosted --load-image",
86-
"cwd": "${workspaceFolder}/references/v3-catalog",
86+
"cwd": "${workspaceFolder}/references/hello-world",
8787
"sourceMaps": true
8888
},
8989
{
9090
"type": "node-terminal",
9191
"request": "launch",
9292
"name": "Debug V3 list-profiles CLI",
9393
"command": "pnpm exec trigger list-profiles --log-level debug",
94-
"cwd": "${workspaceFolder}/references/v3-catalog",
94+
"cwd": "${workspaceFolder}/references/hello-world",
9595
"sourceMaps": true
9696
},
9797
{
9898
"type": "node-terminal",
9999
"request": "launch",
100100
"name": "Debug V3 update CLI",
101101
"command": "pnpm exec trigger update",
102-
"cwd": "${workspaceFolder}/references/v3-catalog",
102+
"cwd": "${workspaceFolder}/references/hello-world",
103103
"sourceMaps": true
104104
},
105105
{
106106
"type": "node-terminal",
107107
"request": "launch",
108108
"name": "Debug V3 Management",
109109
"command": "pnpm run management",
110-
"cwd": "${workspaceFolder}/references/v3-catalog",
110+
"cwd": "${workspaceFolder}/references/hello-world",
111111
"sourceMaps": true
112112
},
113113
{

CONTRIBUTING.md

Lines changed: 15 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -84,17 +84,17 @@ branch are tagged into a release periodically.
8484
8585
2. Once the app is running click the magic link button and enter your email. You will automatically be logged in, since you are running locally. Create an Org and your first project in the dashboard.
8686
87-
## Manual testing using v3-catalog
87+
## Manual testing using hello-world
8888
89-
We use the `<root>/references/v3-catalog` subdirectory as a staging ground for testing changes to the SDK (`@trigger.dev/sdk` at `<root>/packages/trigger-sdk`), the Core package (`@trigger.dev/core` at `<root>packages/core`), the CLI (`trigger.dev` at `<root>/packages/cli-v3`) and the platform (The remix app at `<root>/apps/webapp`). The instructions below will get you started on using the `v3-catalog` for local development of Trigger.dev (v3).
89+
We use the `<root>/references/hello-world` subdirectory as a staging ground for testing changes to the SDK (`@trigger.dev/sdk` at `<root>/packages/trigger-sdk`), the Core package (`@trigger.dev/core` at `<root>packages/core`), the CLI (`trigger.dev` at `<root>/packages/cli-v3`) and the platform (The remix app at `<root>/apps/webapp`). The instructions below will get you started on using the `hello-world` for local development of Trigger.dev.
9090
9191
### First-time setup
9292
9393
First, make sure you are running the webapp according to the instructions above. Then:
9494
95-
1. Visit http://localhost:3030 in your browser and create a new V3 project called "v3-catalog".
95+
1. Visit http://localhost:3030 in your browser and create a new V3 project called "hello-world".
9696
97-
2. In Postgres go to the "Projects" table and for the project you create change the `externalRef` to `yubjwjsfkxnylobaqvqz`.
97+
2. In Postgres go to the "Projects" table and for the project you create change the `externalRef` to `proj_rrkpdguyagvsoktglnod`.
9898
9999
3. Build the CLI
100100
@@ -105,10 +105,10 @@ pnpm run build --filter trigger.dev
105105
pnpm i
106106
```
107107

108-
4. Change into the `<root>/references/v3-catalog` directory and authorize the CLI to the local server:
108+
4. Change into the `<root>/references/hello-world` directory and authorize the CLI to the local server:
109109

110110
```sh
111-
cd references/v3-catalog
111+
cd references/hello-world
112112
cp .env.example .env
113113
pnpm exec trigger login -a http://localhost:3030
114114
```
@@ -118,7 +118,7 @@ This will open a new browser window and authorize the CLI against your local use
118118
You can optionally pass a `--profile` flag to the `login` command, which will allow you to use the CLI with separate accounts/servers. We suggest using a profile called `local` for your local development:
119119

120120
```sh
121-
cd references/v3-catalog
121+
cd references/hello-world
122122
pnpm exec trigger login -a http://localhost:3030 --profile local
123123
# later when you run the dev or deploy command:
124124
pnpm exec trigger dev --profile local
@@ -137,84 +137,29 @@ The following steps should be followed any time you start working on a new featu
137137
pnpm run dev --filter trigger.dev --filter "@trigger.dev/*"
138138
```
139139

140-
3. Open another terminal window, and change into the `<root>/references/v3-catalog` directory.
140+
3. Open another terminal window, and change into the `<root>/references/hello-world` directory.
141141

142-
4. You'll need to run the following commands to setup prisma and migrate the database:
142+
4. Run the `dev` command, which will register all the local tasks with the platform and allow you to start testing task execution:
143143

144144
```sh
145-
pnpm exec prisma migrate deploy
146-
pnpm run generate:prisma
147-
```
148-
149-
5. Run the `dev` command, which will register all the local tasks with the platform and allow you to start testing task execution:
150-
151-
```sh
152-
# in <root>/references/v3-catalog
145+
# in <root>/references/hello-world
153146
pnpm exec trigger dev
154147
```
155148

156149
If you want additional debug logging, you can use the `--log-level debug` flag:
157150

158151
```sh
159-
# in <root>/references/v3-catalog
152+
# in <root>/references/hello-world
160153
pnpm exec trigger dev --log-level debug
161154
```
162155

163-
6. If you make any changes in the CLI/Core/SDK, you'll need to `CTRL+C` to exit the `dev` command and restart it to pickup changes. Any changes to the files inside of the `v3-catalog/src/trigger` dir will automatically be rebuilt by the `dev` command.
164-
165-
7. Navigate to the `v3-catalog` project in your local dashboard at localhost:3030 and you should see the list of tasks.
166-
167-
8. Go to the "Test" page in the sidebar and select a task. Then enter a payload and click "Run test". You can tell what the payloads should be by looking at the relevant task file inside the `/references/v3-catalog/src/trigger` folder. Many of them accept an empty payload.
168-
169-
9. Feel free to add additional files in `v3-catalog/src/trigger` to test out specific aspects of the system, or add in edge cases.
170-
171-
## Running end-to-end webapp tests (deprecated)
156+
6. If you make any changes in the CLI/Core/SDK, you'll need to `CTRL+C` to exit the `dev` command and restart it to pickup changes. Any changes to the files inside of the `hello-world/src/trigger` dir will automatically be rebuilt by the `dev` command.
172157

173-
To run the end-to-end tests, follow the steps below:
174-
175-
1. Set up environment variables (copy example envs into the correct place)
176-
177-
```sh
178-
cp ./.env.example ./.env
179-
cp ./references/nextjs-test/.env.example ./references/nextjs-test/.env.local
180-
```
181-
182-
2. Set up dependencies
183-
184-
```sh
185-
# Build packages
186-
pnpm run build --filter @references/nextjs-test^...
187-
pnpm --filter @trigger.dev/database generate
158+
7. Navigate to the `hello-world` project in your local dashboard at localhost:3030 and you should see the list of tasks.
188159

189-
# Move trigger-cli bin to correct place
190-
pnpm install --frozen-lockfile
160+
8. Go to the "Test" page in the sidebar and select a task. Then enter a payload and click "Run test". You can tell what the payloads should be by looking at the relevant task file inside the `/references/hello-world/src/trigger` folder. Many of them accept an empty payload.
191161

192-
# Install playwrite browsers (ONE TIME ONLY)
193-
npx playwright install
194-
```
195-
196-
3. Set up the database
197-
198-
```sh
199-
pnpm run docker
200-
pnpm run db:migrate
201-
pnpm run db:seed
202-
```
203-
204-
4. Run the end-to-end tests
205-
206-
```sh
207-
pnpm run test:e2e
208-
```
209-
210-
### Cleanup
211-
212-
The end-to-end tests use a `setup` and `teardown` script to seed the database with test data. If the test runner doesn't exit cleanly, then the database can be left in a state where the tests can't run because the `setup` script will try to create data that already exists. If this happens, you can manually delete the `users` and `organizations` from the database using prisma studio:
213-
214-
```sh
215-
# With the database running (i.e. pnpm run docker)
216-
pnpm run db:studio
217-
```
162+
9. Feel free to add additional files in `hello-world/src/trigger` to test out specific aspects of the system, or add in edge cases.
218163

219164
## Adding and running migrations
220165

apps/webapp/app/db.server.ts

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
import {
22
Prisma,
33
PrismaClient,
4-
PrismaClientOrTransaction,
5-
PrismaReplicaClient,
6-
PrismaTransactionClient,
7-
PrismaTransactionOptions,
4+
$transaction as transac,
5+
type PrismaClientOrTransaction,
6+
type PrismaReplicaClient,
7+
type PrismaTransactionClient,
8+
type PrismaTransactionOptions,
89
} from "@trigger.dev/database";
910
import invariant from "tiny-invariant";
1011
import { z } from "zod";
1112
import { env } from "./env.server";
1213
import { logger } from "./services/logger.server";
1314
import { isValidDatabaseUrl } from "./utils/db";
1415
import { singleton } from "./utils/singleton";
15-
import { $transaction as transac } from "@trigger.dev/database";
1616
import { startActiveSpan } from "./v3/tracer.server";
1717
import { Span } from "@opentelemetry/api";
18+
import { queryPerformanceMonitor } from "./utils/queryPerformanceMonitor.server";
1819

1920
export type {
2021
PrismaTransactionClient,
@@ -153,13 +154,19 @@ function getClient() {
153154
},
154155
]
155156
: []) satisfies Prisma.LogDefinition[]),
156-
// verbose
157-
...((process.env.VERBOSE_PRISMA_LOGS === "1"
157+
// Query performance monitoring
158+
...((process.env.VERBOSE_PRISMA_LOGS === "1" ||
159+
process.env.VERY_SLOW_QUERY_THRESHOLD_MS !== undefined
158160
? [
159161
{
160162
emit: "event",
161163
level: "query",
162164
},
165+
]
166+
: []) satisfies Prisma.LogDefinition[]),
167+
// verbose
168+
...((process.env.VERBOSE_PRISMA_LOGS === "1"
169+
? [
163170
{
164171
emit: "stdout",
165172
level: "query",
@@ -206,6 +213,11 @@ function getClient() {
206213
});
207214
}
208215

216+
// Add query performance monitoring
217+
client.$on("query", (log) => {
218+
queryPerformanceMonitor.onQuery("writer", log);
219+
});
220+
209221
// connect eagerly
210222
client.$connect();
211223

@@ -265,13 +277,19 @@ function getReplicaClient() {
265277
},
266278
]
267279
: []) satisfies Prisma.LogDefinition[]),
268-
// verbose
269-
...((process.env.VERBOSE_PRISMA_LOGS === "1"
280+
// Query performance monitoring
281+
...((process.env.VERBOSE_PRISMA_LOGS === "1" ||
282+
process.env.VERY_SLOW_QUERY_THRESHOLD_MS !== undefined
270283
? [
271284
{
272285
emit: "event",
273286
level: "query",
274287
},
288+
]
289+
: []) satisfies Prisma.LogDefinition[]),
290+
// verbose
291+
...((process.env.VERBOSE_PRISMA_LOGS === "1"
292+
? [
275293
{
276294
emit: "stdout",
277295
level: "query",
@@ -317,6 +335,11 @@ function getReplicaClient() {
317335
});
318336
}
319337

338+
// Add query performance monitoring for replica client
339+
replicaClient.$on("query", (log) => {
340+
queryPerformanceMonitor.onQuery("replica", log);
341+
});
342+
320343
// connect eagerly
321344
replicaClient.$connect();
322345

apps/webapp/app/env.server.ts

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ const EnvironmentSchema = z.object({
2323
DATABASE_READ_REPLICA_URL: z.string().optional(),
2424
SESSION_SECRET: z.string(),
2525
MAGIC_LINK_SECRET: z.string(),
26-
ENCRYPTION_KEY: z.string(),
26+
ENCRYPTION_KEY: z
27+
.string()
28+
.refine(
29+
(val) => Buffer.from(val, "utf8").length === 32,
30+
"ENCRYPTION_KEY must be exactly 32 bytes"
31+
),
2732
WHITELISTED_EMAILS: z
2833
.string()
2934
.refine(isValidRegex, "WHITELISTED_EMAILS must be a valid regex.")
@@ -413,6 +418,17 @@ const EnvironmentSchema = z.object({
413418
MARQS_SHARED_WORKER_QUEUE_CONSUMER_INTERVAL_MS: z.coerce.number().int().default(250),
414419
MARQS_SHARED_WORKER_QUEUE_MAX_MESSAGE_COUNT: z.coerce.number().int().default(10),
415420

421+
MARQS_SHARED_WORKER_QUEUE_EAGER_DEQUEUE_ENABLED: z.string().default("0"),
422+
MARQS_WORKER_ENABLED: z.string().default("0"),
423+
MARQS_WORKER_COUNT: z.coerce.number().int().default(2),
424+
MARQS_WORKER_CONCURRENCY_LIMIT: z.coerce.number().int().default(50),
425+
MARQS_WORKER_CONCURRENCY_TASKS_PER_WORKER: z.coerce.number().int().default(5),
426+
MARQS_WORKER_POLL_INTERVAL_MS: z.coerce.number().int().default(100),
427+
MARQS_WORKER_IMMEDIATE_POLL_INTERVAL_MS: z.coerce.number().int().default(100),
428+
MARQS_WORKER_SHUTDOWN_TIMEOUT_MS: z.coerce.number().int().default(60_000),
429+
MARQS_SHARED_WORKER_QUEUE_COOLOFF_COUNT_THRESHOLD: z.coerce.number().int().default(10),
430+
MARQS_SHARED_WORKER_QUEUE_COOLOFF_PERIOD_MS: z.coerce.number().int().default(5_000),
431+
416432
PROD_TASK_HEARTBEAT_INTERVAL_MS: z.coerce.number().int().optional(),
417433

418434
VERBOSE_GRAPHILE_LOGGING: z.string().default("false"),
@@ -485,7 +501,10 @@ const EnvironmentSchema = z.object({
485501
RUN_ENGINE_RETRY_WARM_START_THRESHOLD_MS: z.coerce.number().int().default(30_000),
486502
RUN_ENGINE_PROCESS_WORKER_QUEUE_DEBOUNCE_MS: z.coerce.number().int().default(200),
487503
RUN_ENGINE_DEQUEUE_BLOCKING_TIMEOUT_SECONDS: z.coerce.number().int().default(10),
488-
RUN_ENGINE_MASTER_QUEUE_CONSUMERS_INTERVAL_MS: z.coerce.number().int().default(500),
504+
RUN_ENGINE_MASTER_QUEUE_CONSUMERS_INTERVAL_MS: z.coerce.number().int().default(1000),
505+
RUN_ENGINE_MASTER_QUEUE_COOLOFF_PERIOD_MS: z.coerce.number().int().default(10_000),
506+
RUN_ENGINE_MASTER_QUEUE_COOLOFF_COUNT_THRESHOLD: z.coerce.number().int().default(10),
507+
RUN_ENGINE_MASTER_QUEUE_CONSUMER_DEQUEUE_COUNT: z.coerce.number().int().default(10),
489508
RUN_ENGINE_CONCURRENCY_SWEEPER_SCAN_SCHEDULE: z.string().optional(),
490509
RUN_ENGINE_CONCURRENCY_SWEEPER_PROCESS_MARKED_SCHEDULE: z.string().optional(),
491510
RUN_ENGINE_CONCURRENCY_SWEEPER_SCAN_JITTER_IN_MS: z.coerce.number().int().optional(),
@@ -500,6 +519,14 @@ const EnvironmentSchema = z.object({
500519
RUN_ENGINE_RUN_LOCK_JITTER_FACTOR: z.coerce.number().default(0.15),
501520
RUN_ENGINE_RUN_LOCK_MAX_TOTAL_WAIT_TIME: z.coerce.number().int().default(15000),
502521

522+
RUN_ENGINE_SUSPENDED_HEARTBEAT_RETRIES_MAX_COUNT: z.coerce.number().int().default(12),
523+
RUN_ENGINE_SUSPENDED_HEARTBEAT_RETRIES_MAX_DELAY_MS: z.coerce
524+
.number()
525+
.int()
526+
.default(60_000 * 60 * 6),
527+
RUN_ENGINE_SUSPENDED_HEARTBEAT_RETRIES_INITIAL_DELAY_MS: z.coerce.number().int().default(60_000),
528+
RUN_ENGINE_SUSPENDED_HEARTBEAT_RETRIES_FACTOR: z.coerce.number().default(2),
529+
503530
RUN_ENGINE_WORKER_REDIS_HOST: z
504531
.string()
505532
.optional()
@@ -1064,6 +1091,8 @@ const EnvironmentSchema = z.object({
10641091
AI_RUN_FILTER_MODEL: z.string().optional(),
10651092

10661093
EVENT_LOOP_MONITOR_THRESHOLD_MS: z.coerce.number().int().default(100),
1094+
1095+
VERY_SLOW_QUERY_THRESHOLD_MS: z.coerce.number().int().optional(),
10671096
});
10681097

10691098
export type Environment = z.infer<typeof EnvironmentSchema>;

0 commit comments

Comments
 (0)