Skip to content

Lots of small docs improvements #1251

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 4 additions & 4 deletions docs/apikeys.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
43 changes: 43 additions & 0 deletions docs/cli-dev.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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>
19 changes: 9 additions & 10 deletions docs/github-actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Binary file added docs/images/lifecycle-functions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/run-page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/terminal-completed-run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/test-page.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/limits.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
18 changes: 9 additions & 9 deletions docs/machines.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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).
2 changes: 1 addition & 1 deletion docs/migration-defer.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
12 changes: 7 additions & 5 deletions docs/mint.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@
},
"topbarLinks": [
{
"name": "Community",
"name": "v2 docs",
"url": "https://v2docs.trigger.dev/documentation/introduction"
},
{
"name": "Discord",
"url": "https://trigger.dev/discord"
}
],
Expand Down Expand Up @@ -85,10 +89,8 @@
"tasks-overview",
"triggering",
"apikeys",
{
"group": "Task types",
"pages": ["tasks-regular", "tasks-scheduled"]
},
"tasks-regular",
"tasks-scheduled",
"trigger-config"
]
},
Expand Down
8 changes: 5 additions & 3 deletions docs/snippets/step-run-test.mdx
Original file line number Diff line number Diff line change
@@ -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>
6 changes: 5 additions & 1 deletion docs/snippets/step-view-run.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 4 additions & 0 deletions docs/tasks-overview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions docs/tasks-scheduled.mdx
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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

```
* * * * *
Expand All @@ -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

Expand Down Expand Up @@ -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. |
Expand All @@ -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",
Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions docs/triggering.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
52 changes: 52 additions & 0 deletions docs/troubleshooting.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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"
},
}
```
2 changes: 1 addition & 1 deletion docs/wait-for.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 />
2 changes: 1 addition & 1 deletion docs/wait-until.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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 />

Expand Down
Loading