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
description: "Understand how Trigger.dev works and how it can help you."
5
5
---
6
6
7
+
## Introduction
8
+
7
9
Trigger.dev v3 allows you to embed long-running async tasks into your application and run them in the background. This allows you to offload tasks that take a long time to complete, such as sending emails, processing videos, or running long chains of AI tasks.
8
10
9
11
For example, the below task processes a video with `ffmpeg` and sends the results to an s3 bucket, then updates a database with the results and sends an email to the user.
@@ -104,6 +101,25 @@ export async function POST(request: Request) {
104
101
105
102
This will schedule the task to run in the background and return a handle that you can use to check the status of the task. This allows your backend application to respond quickly to the user and offload the long-running task to Trigger.dev.
106
103
104
+
## The CLI
105
+
106
+
Trigger.dev comes with a CLI that allows you to initialize Trigger.dev into your project, deploy your tasks, and run your tasks locally. You can run it via `npx` like so:
107
+
108
+
```sh
109
+
npx trigger.dev@latest login # Log in to your Trigger.dev account
110
+
npx trigger.dev@latest init # Initialize Trigger.dev in your project
111
+
npx trigger.dev@latest dev # Run your tasks locally
112
+
npx trigger.dev@latest deploy # Deploy your tasks to the Trigger.dev instance
113
+
```
114
+
115
+
All these commands work with the Trigger.dev cloud and/or your self-hosted instance. It supports multiple profiles so you can easily switch between different accounts or instances.
116
+
117
+
```sh
118
+
npx trigger.dev@latest login --profile <profile> -a https://trigger.example.com # Log in to a specific profile into a self-hosted instance
119
+
npx trigger.dev@latest dev --profile <profile># Initialize Trigger.dev in your project
120
+
npx trigger.dev@latest deploy --profile <profile># Deploy your tasks to the Trigger.dev instance
121
+
```
122
+
107
123
## Trigger.dev architecture
108
124
109
125
Trigger.dev implements a serverless architecture (without timeouts!) that allows you to run your tasks in a scalable and reliable way. When you run `npx trigger.dev@latest deploy`, we build and deploy your task code to your Trigger.dev instance. Then, when you trigger a task from your application, it's run in a secure, isolated environment with the resources you need to complete the task. A simplified diagram for a task execution looks like this:
@@ -233,36 +249,37 @@ Let's rewrite the `convert-video` task above to be more durable:
`Your video has been processed and is available at: ${s3Url}`
@@ -374,14 +402,50 @@ sequenceDiagram
374
402
375
403
## The build system
376
404
377
-
When you run `npx trigger.dev@latest deploy` or `npx trigger.dev@latest dev`, we build your task code using our build system, which is powered by esbuild. When deploying, the code is packaged up into a Docker image and deployed to your Trigger.dev instance. When running in development mode, the code is built and run locally on your machine. Some features of our build system include:
405
+
When you run `npx trigger.dev@latest deploy` or `npx trigger.dev@latest dev`, we build your task code using our build system, which is powered by [esbuild](https://esbuild.github.io/). When deploying, the code is packaged up into a Docker image and deployed to your Trigger.dev instance. When running in dev mode, the code is built and run locally on your machine. Some features of our build system include:
378
406
379
407
-**Bundled by default**: Code + dependencies are bundled and tree-shaked by default.
380
408
-**Build extensions**: Use and write custom build extensions to transform your code or the resulting docker image.
381
409
-**ESM ouput**: We output to ESM, which allows tree-shaking and better performance.
382
410
383
-
You can learn more about working with our build system in the [configuration docs](/config/config-file).
411
+
You can review the build output by running deploy with the `--dry-run` flag, which will output the Containerfile and the build output.
412
+
413
+
Learn more about working with our build system in the [configuration docs](/config/config-file).
414
+
415
+
## Dev mode
416
+
417
+
When you run `npx trigger.dev@latest dev`, we run your task code locally on your machine. All scheduling is still done in the Trigger.dev server instance, but the task code is run locally. This allows you to develop and test your tasks locally before deploying them to the cloud, and is especially useful for debugging and testing.
418
+
419
+
- The same build system is used in dev mode, so you can be sure that your code will run the same locally as it does in the cloud.
420
+
- Changes are automatically detected and a new version is spun up when you save your code.
421
+
- Add debuggers and breakpoints to your code and debug it locally.
422
+
- Each task is run in a separate process, so you can run multiple tasks in parallel.
423
+
- Auto-cancels tasks when you stop the dev server.
424
+
425
+
<Note>
426
+
Trigger.dev currently does not support "offline" dev mode, where you can run tasks without an
427
+
internet connection. Please let us know if this is a feature you want/need.
428
+
</Note>
429
+
430
+
## Staging and production environments
431
+
432
+
Trigger.dev supports deploying to multiple "deployed" environments, such as staging and production. This allows you to test your tasks in a staging environment before deploying them to production. You can deploy to a new environment by running `npx trigger.dev@latest deploy --env <env>`, where `<env>` is the name of the environment you want to deploy to. Each environment has its own API Key, which you can use to trigger tasks in that environment.
384
433
385
434
## OpenTelemetry
386
435
387
-
The Trigger.dev logging and task dashboard is powered by OpenTelemetry traces and logs, which allows you to trace your tasks and auto-instrument your code.
436
+
The Trigger.dev logging and task dashboard is powered by OpenTelemetry traces and logs, which allows you to trace your tasks and auto-instrument your code. We also auto-correlate logs from subtasks and parent tasks, making it easy view the entire trace of a task execution. A single run of the video processing task above looks like this in the dashboard:
Because we use standard OpenTelemetry, you can instrument your code and OpenTelemetry compatible libraries to get detailed traces and logs of your tasks. The above trace instruments both Prisma and the AWS SDK:
0 commit comments