You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Almost all commands in the monorepo should be executed when `pnpm run ...` from the root of the monorepo. For example, running tests for the `@internal/run-engine` internal package:
7
+
8
+
```
9
+
pnpm run dev --filter webapp
10
+
```
11
+
12
+
But often, when running tests, it's better to `cd` into the directory and then run tests:
description: Making updates to the main trigger.dev remix webapp
3
+
globs: apps/webapp/**/*.tsx,apps/webapp/**/*.ts
4
+
alwaysApply: false
5
+
---
6
+
7
+
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:
8
+
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)
10
+
- `@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)
11
+
- `@internal/run-engine` has all the code needed to trigger a run and take it through it's lifecycle to completion.
12
+
- `@internal/redis-worker` is a custom redis based background job/worker system that's used in the webapp and also used inside the run engine.
13
+
14
+
## Environment variables and testing
15
+
16
+
In the webapp, all environment variables are accessed through the `env` export of [env.server.ts](mdc:apps/webapp/app/env.server.ts), instead of directly accessing `process.env`.
17
+
18
+
Ideally, the `env.server.ts` file would never be imported into a test file, either directly or indirectly. Tests should only imported classes and functions from a file matching `app/**/*.ts` of the webapp, and that file should not use environment variables, everything should be passed through as options instead. This "service/configuration" separation is important, and can be seen in a few places in the code for examples:
19
+
20
+
- [realtimeClient.server.ts](mdc:apps/webapp/app/services/realtimeClient.server.ts) is the testable service, and [realtimeClientGlobal.server.ts](mdc:apps/webapp/app/services/realtimeClientGlobal.server.ts) is the configuration
21
+
22
+
Also for writing tests in the webapp, checkout our [tests.md](mdc:ai/references/tests.md) guide
23
+
24
+
## Legacy run engine vs Run Engine 2.0
25
+
26
+
We originally the Trigger.dev "Run Engine" not as a single system, but just spread out all over the codebase, with no real separate or encapsulation. And we didn't even call it a "Run Engine". With Run Engine 2.0, we've completely rewritten big parts of the way the system works, and moved it over to an internal package called `@internal/run-engine`. So we've retroactively named the previous run engine "Legacy run engine". We're focused almost exclusively now on moving to Run Engine 2.0 and will be deprecating and removing the legacy run engine code eventually.
27
+
28
+
## Where to look for code
29
+
30
+
- The trigger API endpoint is [api.v1.tasks.$taskId.trigger.ts](mdc:apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts)
31
+
- The batch trigger API endpoint is [api.v1.tasks.batch.ts](mdc:apps/webapp/app/routes/api.v1.tasks.batch.ts)
32
+
- Setup code for the prisma client is in [db.server.ts](mdc:apps/webapp/app/db.server.ts)
33
+
- 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
35
+
- 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
Copy file name to clipboardExpand all lines: CONTRIBUTING.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -135,23 +135,22 @@ The following steps should be followed any time you start working on a new featu
135
135
136
136
1. Make sure the webapp is running on localhost:3030
137
137
138
-
2. Open a terminal window and build the CLI and watch for changes
138
+
2. Open a terminal window and build the CLI and packages and watch for changes
139
139
140
140
```sh
141
-
pnpm run dev --filter trigger.dev
141
+
pnpm run dev --filter trigger.dev --filter "@trigger.dev/*"
142
142
```
143
143
144
-
2. Open a new terminal window, and anytime changes are made to the `@trigger.dev/core` package, you'll need to manually rebuild the CLI:
144
+
3. Open another terminal window, and change into the `<root>/references/v3-catalog` directory.
145
+
146
+
4. You'll need to run the following commands to setup prisma and migrate the database:
145
147
146
148
```sh
147
-
pnpm run build --filter trigger.dev
149
+
pnpm exec prisma migrate deploy
150
+
pnpm run generate:prisma
148
151
```
149
152
150
-
Note: You do not need to do the same for `@trigger.dev/sdk`, just core.
151
-
152
-
3. Open another terminal window, and change into the `<root>/references/v3-catalog` directory.
153
-
154
-
4. Run the `dev` command, which will register all the local tasks with the platform and allow you to start testing task execution:
153
+
5. Run the `dev` command, which will register all the local tasks with the platform and allow you to start testing task execution:
155
154
156
155
```sh
157
156
# in <root>/references/v3-catalog
@@ -165,13 +164,13 @@ If you want additional debug logging, you can use the `--log-level debug` flag:
165
164
pnpm exec trigger dev --log-level debug
166
165
```
167
166
168
-
5. 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.
167
+
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.
169
168
170
-
6. Navigate to the `v3-catalog` project in your local dashboard at localhost:3030 and you should see the list of tasks.
169
+
7. Navigate to the `v3-catalog` project in your local dashboard at localhost:3030 and you should see the list of tasks.
171
170
172
-
7. 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.
171
+
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.
173
172
174
-
8. Feel free to add additional files in `v3-catalog/src/trigger` to test out specific aspects of the system, or add in edge cases.
173
+
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.
175
174
176
175
## Running end-to-end webapp tests (deprecated)
177
176
@@ -240,11 +239,12 @@ pnpm run db:studio
240
239
241
240
4. Run the migration.
242
241
243
-
```
244
-
pnpm run db:migrate:deploy
245
-
pnpm run generate
246
-
```
247
-
This executes the migrations against your database and applies changes to the database schema(s), and then regenerates the Prisma client.
242
+
```
243
+
pnpm run db:migrate:deploy
244
+
pnpm run generate
245
+
```
246
+
247
+
This executes the migrations against your database and applies changes to the database schema(s), and then regenerates the Prisma client.
248
248
249
249
4. Commit generated migrations as well as changes to the schema.prisma file
250
250
5. If you're using VSCode you may need to restart the Typescript server in the webapp to get updated type inference. Open a TypeScript file, then open the Command Palette (View > Command Palette) and run `TypeScript: Restart TS server`.
This is a pnpm 8.15.5 monorepo that uses turborepo @turbo.json. The following workspaces are relevant
4
+
5
+
## Apps
6
+
7
+
- <root>/apps/webapp is a remix app that is the main API and dashboard for trigger.dev
8
+
- <root>/apps/supervisor is a node.js app that handles the execution of built tasks, interaction with the webapp through internal "engine" APIs, as well as interfacing with things like docker or kubernetes, to execute the code.
9
+
10
+
## Public Packages
11
+
12
+
- <root>/packages/trigger-sdk is the `@trigger.dev/sdk` main SDK package.
13
+
- <root>/packages/cli-v3 is the `trigger.dev` CLI package. See our [CLI dev command](https://trigger.dev/docs/cli-dev.md) and [Deployment](https://trigger.dev/docs/deployment/overview.md) docs for more information.
14
+
- <root>/packages/core is the `@trigger.dev/core` package that is shared across the SDK and other packages
15
+
- <root>/packages/build defines the types and prebuilt build extensions for trigger.dev. See our [build extensions docs](https://trigger.dev/docs/config/extensions/overview.md) for more information.
16
+
- <root>/packages/react-hooks defines some useful react hooks like our realtime hooks. See our [Realtime hooks](https://trigger.dev/docs/frontend/react-hooks/realtime.md) and our [Trigger hooks](https://trigger.dev/docs/frontend/react-hooks/triggering.md) for more information.
17
+
18
+
## Internal Packages
19
+
20
+
- <root>/internal-packages/\* are packages that are used internally only, not published, and usually they have a tsc build step and are used in the webapp
21
+
- <root>/internal-packages/database is the `@trigger.dev/database` package that exports a prisma client, has the schema file, and exports a few other helpers.
22
+
- <root>/internal-packages/run-engine is the `@internal/run-engine` package that is "Run Engine 2.0" and handles moving a run all the way through it's lifecycle
23
+
- <root>/internal-packages/redis-worker is the `@internal/redis-worker` package that implements a custom background job/worker sytem powered by redis for offloading work to the background, used in the webapp and also in the Run Engine 2.0.
24
+
- <root>/internal-packages/redis is the `@internal/redis` package that exports Redis types and the `createRedisClient` function to unify how we create redis clients in the repo. It's not used everywhere yet, but it's the preferred way to create redis clients from now on.
25
+
- <root>/internal-packages/testcontainers is the `@internal/testcontainers` package that exports a few useful functions for spinning up local testcontainers when writing vitest tests. See our [tests.md](./tests.md) file for more information.
26
+
- <root>/internal-packages/zodworker is the `@internal/zodworker` package that implements a wrapper around graphile-worker that allows us to use zod to validate our background jobs. We are moving away from using graphile-worker as our background job system, replacing it with our own redis-worker package.
27
+
28
+
## References
29
+
30
+
- <root>/references/\* are test workspaces that we use to write and test the system. Not quite e2e tests or automated, but just a useful place to help develop new features
31
+
32
+
## Other
33
+
34
+
- <root>/docs is our trigger.dev/docs mintlify documentation site
35
+
- <root>/docker/Dockerfile is the one that creates the main trigger.dev published image
36
+
- <root>/docker/docker-compose.yml is the file we run locally to start postgresql, redis, and electric when we are doing local development. You can run it with `pnpm run docker`
37
+
- <root>/CONTRIBUTING.md defines the steps it takes for OSS contributors to start contributing.
We use vitest exclusively for testing. To execute tests for a particular workspace, run the following command:
4
+
5
+
```bash
6
+
pnpm run test --filter webapp
7
+
```
8
+
9
+
Prefer running tests on a single file (and first cding into the directory):
10
+
11
+
```bash
12
+
cd apps/webapp
13
+
pnpm run test ./src/components/Button.test.ts
14
+
```
15
+
16
+
If you are cd'ing into a directory, you may have to build dependencies first:
17
+
18
+
```bash
19
+
pnpm run build --filter webapp
20
+
cd apps/webapp
21
+
pnpm run test ./src/components/Button.test.ts
22
+
```
23
+
24
+
## Writing Tests
25
+
26
+
We use vitest for testing. We almost NEVER mock anything. Start with a top-level "describe", and have multiple "it" statements inside of it.
27
+
28
+
When writing anything that needs redis or postgresql, we have some internal "testcontainers" that are used to spin up a local instance, redis, or both.
0 commit comments