Lots of small docs improvements (#1251)

* tasks no longer inside a group in the side menu (and added “cron”)

* Delay using a timezone

* Added React Not Defined error to the troubleshooting page

* Improved the React common problem

* Link to v2 docs

* New Development section and entry in Common Problems

* Concurrently running the terminal

* Fixed the .env weirdness

* Added section on creating PATs for Github actions

* Improved the Machine spec and limits page

* Quick start steps now have nice images

* Added a diagram for the lifecycle functions

* Added note about onFailure

* CRON -> cron/Cron

* Updated the cli-dev steps for the concurrently package

* Fixed capital letter

* Updated diagram text

* Removed dead page
This commit is contained in:
James Ritchie
2024-08-08 15:03:05 +01:00
committed by GitHub
parent bf1482fdb9
commit 0d4e3e70c1
20 changed files with 158 additions and 44 deletions
@@ -119,7 +119,7 @@ const pricingDefinitions = {
},
schedules: {
title: "Schedules",
content: "You can attach recurring schedules to tasks using CRON syntax.",
content: "You can attach recurring schedules to tasks using cron syntax.",
},
alerts: {
title: "Alert destination",
+4 -4
View File
@@ -15,14 +15,14 @@ Each environment has its own secret key. You can find the value on the API keys
To automatically configure the SDK with your secret key, you can set the `TRIGGER_SECRET_KEY` environment variable. The SDK will automatically use this value when calling API methods (like `trigger`).
```bash
export TRIGGER_SECRET_KEY=tr_dev_…
```bash .env
TRIGGER_SECRET_KEY="tr_dev_…"
```
You can do the same if you are self-hosting and need to change the default URL by using `TRIGGER_API_URL`.
```bash
export TRIGGER_API_URL=https://trigger.example.com
```bash .env
TRIGGER_API_URL="https://trigger.example.com"
```
The default URL is `https://api.trigger.dev`.
+43
View File
@@ -48,3 +48,46 @@ yarn dlx trigger.dev@beta dev --debugger
```
</CodeGroup>
### Concurrently running the terminal
The concurrently package allows you to run multiple package.json scripts at the same time in this case, your site and Trigger.dev.
<Steps>
<Step title="Install the concurrently package as a dev dependency">
<CodeGroup>
```bash npm
npm i concurrently -D
```
```bash pnpm
pnpm i concurrently -D
```
```bash yarn
yarn i concurrently -D
```
</CodeGroup>
</Step>
<Step title="Update your package.json">
Then add something like this in your package.json scripts. This assumes you're running Next.js so swap that bit out if you're not:
```json
"scripts": {
"dev": "concurrently --raw --kill-others npm:dev:*",
"dev:next": "next dev",
"dev:trigger": "npx trigger.dev@beta dev",
//...
}
```
</Step>
</Steps>
+9 -10
View File
@@ -77,20 +77,19 @@ jobs:
If you already have a GitHub action file, you can just add the final step "🚀 Deploy Trigger.dev" to your existing file.
You need to add the `TRIGGER_ACCESS_TOKEN` secret to your repository. You can create a new access token by going to your profile page and then clicking on the ["Personal Access Tokens"](https://cloud.trigger.dev/account/tokens) tab.
### Creating a Personal Access Token
To set it in GitHub go to your repository, click on "Settings", "Secrets and variables" and then "Actions". Add a new secret with the name `TRIGGER_ACCESS_TOKEN` and use the value of your access token.
<Steps>
<Accordion title="How to add TRIGGER_ACCESS_TOKEN in GitHub">
1. Go to your repository on GitHub.
2. Click on "Settings".
3. Click on "Secrets and variables" -> "Actions"
4. Click on "New repository secret".
5. Add the name `TRIGGER_ACCESS_TOKEN` and the value of your access token.
<Step title="Create a new access token">Go to your profile page and click on the ["Personal Access Tokens"](https://cloud.trigger.dev/account/tokens) tab.</Step>
<Step title="Go to your repository on GitHub.">Click on 'Settings' -> 'Secrets and variables' -> 'Actions' -> 'New repository secret'</Step>
<Step title="Add the TRIGGER_ACCESS_TOKEN">Add the name `TRIGGER_ACCESS_TOKEN` and the value of your access token. ![Add TRIGGER_ACCESS_TOKEN in GitHub](/images/github-access-token.png)</Step>
</Steps>
![Add TRIGGER_ACCESS_TOKEN in GitHub](/images/github-access-token.png)
</Accordion>
## Version pinning
Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 656 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 291 KiB

+6
View File
@@ -49,3 +49,9 @@ If you're creating schedules for your user you will definitely need to request m
| Task outputs | Must not exceed 10MB |
Payloads and outputs that exceed 512KB will be offloaded to object storage and a presigned URL will be provided to download the data when calling `runs.retrieve`. You don't need to do anything to handle this in your tasks however, as we will transparently upload/download these during operation.
### Machines
The default machine is `small-1x` which has 0.5 vCPU and 0.5 GB of RAM. You can optionally configure a higher spec machine which will increase the cost of running the task but can also improve the performance of the task if it is CPU or memory bound.
See the [machine configurations](/machines#machine-configurations) for more details.
+9 -9
View File
@@ -30,14 +30,14 @@ export const config: TriggerConfig = {
## Machine configurations
| Preset | vCPU | Memory |
| --------- | ---- | ------ |
| micro | 0.25 | 0.25 |
| small-1x | 0.5 | 0.5 |
| small-2x | 1 | 1 |
| medium-1x | 1 | 2 |
| medium-2x | 2 | 4 |
| large-1x | 4 | 8 |
| large-2x | 8 | 16 |
| Preset | vCPU | Memory | Disk space |
| ------------------- | ---- | ------ | ---------- |
| micro | 0.25 | 0.25 | 10GB |
| small-1x (default) | 0.5 | 0.5 | 10GB |
| small-2x | 1 | 1 | 10GB |
| medium-1x | 1 | 2 | 10GB |
| medium-2x | 2 | 4 | 10GB |
| large-1x | 4 | 8 | 10GB |
| large-2x | 8 | 16 | 10GB |
You can view the Trigger.dev cloud pricing for these machines [here](https://trigger.dev/pricing#computePricing).
+1 -1
View File
@@ -240,7 +240,7 @@ export async function runLongRunningTask() {
to trigger tasks from your code. See the [API keys page](/apikeys) for more information.
</Warning>
#### Example 2: A CRON task
#### Example 2: A cron task
We call these [scheduled tasks](/tasks-scheduled) in Trigger.dev.
+7 -5
View File
@@ -43,7 +43,11 @@
},
"topbarLinks": [
{
"name": "Community",
"name": "v2 docs",
"url": "https://v2docs.trigger.dev/documentation/introduction"
},
{
"name": "Discord",
"url": "https://trigger.dev/discord"
}
],
@@ -85,10 +89,8 @@
"tasks-overview",
"triggering",
"apikeys",
{
"group": "Task types",
"pages": ["tasks-regular", "tasks-scheduled"]
},
"tasks-regular",
"tasks-scheduled",
"trigger-config"
]
},
+5 -3
View File
@@ -1,9 +1,11 @@
<Step title="Perform a test run using the dashboard">
The CLI `dev` command spits out various useful URLs. Right now we want to visit the Test page it provided.
The CLI `dev` command spits out various useful URLs. Right now we want to visit the Test page <Icon icon="circle-1" iconType="solid" size={20} color="F43F47" />.
You should see our Example task in the list, select it. Most tasks have a "payload" which you enter in the JSON editor, but our example task doesn't need any input.
You should see our Example task in the list <Icon icon="circle-2" iconType="solid" size={20} color="F43F47" />, select it. Most tasks have a "payload" which you enter in the JSON editor <Icon icon="circle-3" iconType="solid" size={20} color="F43F47" />, but our example task doesn't need any input.
Press the "Run test" button.
Press the "Run test" button <Icon icon="circle-4" iconType="solid" size={20} color="F43F47" />.
![Test page](/images/test-page.png)
</Step>
+5 -1
View File
@@ -2,6 +2,10 @@
Congratulations, you should see the run page which will live reload showing you the current state of the run.
If you go back to your terminal you'll see that the dev command also shows tasks that are running and links to the run log.
![Run page](/images/run-page.png)
If you go back to your terminal you'll see that the dev command also shows the task status and links to the run log.
![Terminal showing completed run](/images/terminal-completed-run.png)
</Step>
+4
View File
@@ -121,6 +121,10 @@ export const heavyTask = task({
});
```
## Lifecycle functions
![Lifecycle functions](/images/lifecycle-functions.png)
### `init` function
This function is called before a run attempt:
+8 -8
View File
@@ -1,6 +1,6 @@
---
title: "Scheduled tasks"
description: "A task that is triggered on a recurring schedule using CRON syntax."
title: "Scheduled tasks (cron)"
description: "A task that is triggered on a recurring schedule using cron syntax."
---
## Defining a scheduled task
@@ -120,7 +120,7 @@ To use imperative schedules you need to do two things:
1. Define a task in your code using `schedules.task()`.
2. Attach 1+ schedules to the task either using the dashboard or the SDK.
## Supported CRON syntax
## Supported cron syntax
```
* * * * *
@@ -135,7 +135,7 @@ To use imperative schedules you need to do two things:
"L" means the last. In the "day of week" field, 1L means the last Monday of the month. In the "day of month" field, L means the last day of the month.
We do not support seconds in the CRON syntax.
We do not support seconds in the cron syntax.
## When schedules won't trigger
@@ -165,7 +165,7 @@ These are the options when creating a schedule:
| Name | Description |
| ----------------- | --------------------------------------------------------------------------------------------- |
| Task | The id of the task you want to attach to. |
| CRON pattern | The schedule in CRON format. |
| Cron pattern | The schedule in cron format. |
| Timezone | The timezone the schedule will run in. Defaults to "UTC" |
| External id | An optional external id, usually you'd use a userId. |
| Deduplication key | An optional deduplication key. If you pass the same value, it will update rather than create. |
@@ -183,7 +183,7 @@ You call `schedules.create()` to create a schedule from your code. Here's the si
const createdSchedule = await schedules.create({
//The id of the scheduled task you want to attach to.
task: firstScheduledTask.id,
//The schedule in CRON format.
//The schedule in cron format.
cron: "0 0 * * *",
//this is required, it prevents you from creating duplicate schedules. It will update the schedule if it already exists.
deduplicationKey: "my-deduplication-key",
@@ -200,14 +200,14 @@ This means you can have thousands of schedules attached to a single task, but on
const createdSchedule = await schedules.create({
//The id of the scheduled task you want to attach to.
task: firstScheduledTask.id,
//The schedule in CRON format.
//The schedule in cron format.
cron: "0 0 * * *",
// Optional, it defaults to "UTC". In IANA format, e.g. "America/New_York".
// In this case, the task will run at midnight every day in New York time.
// If you specify a timezone it will automatically work with daylight saving time.
timezone: "America/New_York",
//Optionally, you can specify your own IDs (like a user ID) and then use it inside the run function of your task.
//This allows you to have per-user CRON tasks.
//This allows you to have per-user cron tasks.
externalId: "user_123456",
//You can only create one schedule with this key.
//If you use it twice, the second call will update the schedule.
+2
View File
@@ -446,6 +446,8 @@ await myTask.trigger({ some: "data" }, { delay: "1h52m18s" });
await myTask.trigger({ some: "data" }, { delay: "2024-12-01T00:00:00" });
// Delay using a Date object
await myTask.trigger({ some: "data" }, { delay: new Date(Date.now() + 1000 * 60 * 60) });
// Delay using a timezone
await myTask.trigger({ some: "data" }, { delay: new Date('2024-07-23T11:50:00+02:00') });
```
Runs that are delayed and have not been enqueued yet will display in the dashboard with a "Delayed" status:
+52
View File
@@ -3,6 +3,29 @@ title: "Common problems"
description: "Some common problems you might experience and their solutions"
---
## Development
### `EACCES: permission denied`
If you see this error:
```ts
6090 verbose stack Error: EACCES: permission denied, rename '/Users/user/.npm/_cacache/tmp/f1bfea11' -> '/Users/user/.npm/_cacache/content-v2/sha512/31/d8/e094a47a0105d06fd246892ed1736c02eae323726ec6a3f34734eeb71308895dfba4f4f82a88ffe7e480c90b388c91fc3d9f851ba7b96db4dc33fbc65528'
```
First, clear the npm cache:
```ts
npm cache clean --force
```
Then change the permissions of the npm folder (if 1 doesn't work):
```ts
sudo chown -R $(whoami) ~/.npm
```
## Deployment
Running the [trigger.dev deploy] command builds and deploys your code. Sometimes there can be issues building your code.
@@ -82,6 +105,10 @@ Prisma uses code generation to create the client from your schema file. This mea
Make sure that you always use `await` when you call `trigger`, `triggerAndWait`, `batchTrigger`, and `batchTriggerAndWait`. If you don't then it's likely the task(s) won't be triggered because the calling function process can be terminated before the networks calls are sent.
### `Error: Prisma generate failed to find the specified schema at ../../path`
## Framework specific issues
### NestJS swallows all errors/exceptions
@@ -102,3 +129,28 @@ export const simplestTask = task({
```
NestJS has a global exception filter that catches all errors and swallows them, so we can't receive them. Our current recommendation is to not use NestJS inside your tasks. If you're a NestJS user you can still use Trigger.dev but just don't use NestJS inside your tasks like this.
### React is not defined
If you see this error:
```ts
Worker failed to start ReferenceError: React is not defined
```
Either add this to your file:
```ts
import React from "react";
```
Or change the tsconfig jsx setting:
```json
{
"compilerOptions": {
//...
"jsx": "react-jsx"
},
}
```
+1 -1
View File
@@ -28,6 +28,6 @@ export const veryLongTask = task({
});
```
This allows you to write linear code without having to worry about the complexity of scheduling or managing CRON jobs.
This allows you to write linear code without having to worry about the complexity of scheduling or managing cron jobs.
<PausedExecutionFree />
+1 -1
View File
@@ -25,7 +25,7 @@ export const sendReminderEmail = task({
});
```
This allows you to write linear code without having to worry about the complexity of scheduling or managing CRON jobs.
This allows you to write linear code without having to worry about the complexity of scheduling or managing cron jobs.
<PausedExecutionFree />