Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
af4bdde
Fixed empty env vars overriding in dev runs
ericallam Sep 6, 2024
32c3928
Don’t import package.json anymore
ericallam Sep 6, 2024
f11740e
fix node10 moduleResolution in @trigger.dev/core
ericallam Sep 6, 2024
1ce6c86
Support self-hosters pushing to a custom registry when running deploy
ericallam Sep 6, 2024
0287cd8
dev: Fixed stuck runs when a child run fails with a process exit
ericallam Sep 6, 2024
3f92690
Make some doc notes about known issues and docker hub private repos
ericallam Sep 6, 2024
7d5e62b
Fix --project-ref when running deploy
ericallam Sep 6, 2024
f788471
Fix —config option when deploying
ericallam Sep 9, 2024
cc5f0e1
Fixing the flushing/killing process with the new build system
ericallam Sep 9, 2024
ae540ca
Add monorepo-react-email e2e test fixture
ericallam Sep 9, 2024
aae6520
Fix issue with emitDecoratorMetadata and tsconfigs with extends
ericallam Sep 10, 2024
39fbc54
Got the emit decorator metadata fixture working
ericallam Sep 10, 2024
e5aac92
Fixed typechecking yarn e2e CLI tests in monorepos
ericallam Sep 10, 2024
32e46e0
Add remote forced externals system, in case we come across another pa…
ericallam Sep 10, 2024
88cfe18
Remote externals now powered by JSON Hero to be easier to update
ericallam Sep 11, 2024
45fd00f
resolve config source files
ericallam Sep 11, 2024
5bb3989
Add a —javascript option to init, defaults to typescript
ericallam Sep 11, 2024
bc83670
Add support for prisma typed sql
ericallam Sep 11, 2024
4a71a9e
Remove msw and retry.interceptFetch
ericallam Sep 11, 2024
0f47825
Add missing code to the openai retries example
ericallam Sep 11, 2024
c04df58
Don’t generate the v3 catalog prisma client during CI
ericallam Sep 11, 2024
b64093c
Fixed v3-catalog task imports
ericallam Sep 11, 2024
ab39701
Remove interceptor usage in task file
ericallam Sep 11, 2024
bba0a54
Only import import-in-the-middle hook if there are instrumented packages
ericallam Sep 11, 2024
e09767f
Fix yarn.lock file
ericallam Sep 11, 2024
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
5 changes: 5 additions & 0 deletions .changeset/curvy-beers-camp.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Fixed empty env vars overriding in dev runs
5 changes: 5 additions & 0 deletions .changeset/gentle-planets-return.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/build": patch
---

Fix issue with emitDecoratorMetadata and tsconfigs with extends
7 changes: 7 additions & 0 deletions .changeset/mighty-sheep-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@trigger.dev/sdk": patch
"trigger.dev": patch
"@trigger.dev/core": patch
---

Support self-hosters pushing to a custom registry when running deploy
5 changes: 5 additions & 0 deletions .changeset/proud-dogs-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/build": patch
---

Add support for prisma typed sql
5 changes: 5 additions & 0 deletions .changeset/rude-houses-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Fix --project-ref when running deploy
5 changes: 5 additions & 0 deletions .changeset/strong-years-help.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"trigger.dev": patch
---

Fixed stuck runs when a child run fails with a process exit
6 changes: 6 additions & 0 deletions .changeset/tidy-roses-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"trigger.dev": patch
"@trigger.dev/core": patch
---

Add remote forced externals system, in case we come across another package that cannot be bundled (spurred on by header-generator)
5 changes: 5 additions & 0 deletions .changeset/twenty-seahorses-admire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/sdk": patch
---

Remove msw and retry.interceptFetch
5 changes: 5 additions & 0 deletions .changeset/violet-cherries-deny.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@trigger.dev/core": patch
---

fix node10 moduleResolution in @trigger.dev/core
6 changes: 6 additions & 0 deletions .changeset/wise-pens-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"trigger.dev": patch
"@trigger.dev/core": patch
---

Only import import-in-the-middle hook if there are instrumented packages
19 changes: 9 additions & 10 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@
"url": "http://localhost:3030",
"webRoot": "${workspaceFolder}/apps/webapp/app"
},
{
"type": "node-terminal",
"request": "launch",
"name": "Debug v2 job catalog",
"command": "pnpm run byo-auth",
"envFile": "${workspaceFolder}/references/job-catalog/.env",
"cwd": "${workspaceFolder}/references/job-catalog",
"sourceMaps": true
},
{
"type": "node-terminal",
"request": "launch",
Expand Down Expand Up @@ -89,9 +80,17 @@
"type": "node-terminal",
"request": "launch",
"name": "Debug CLI e2e tests",
"command": "PM=yarn pnpm run test:e2e",
"command": "MOD=otel-telemetry-loader pnpm run test:e2e",
"cwd": "${workspaceFolder}/packages/cli-v3",
"sourceMaps": true
},
{
"type": "node-terminal",
"request": "launch",
"name": "debug v3 hello-world dev",
"command": "pnpm exec triggerdev dev",
"cwd": "${workspaceFolder}/references/hello-world",
"sourceMaps": true
}
]
}
2 changes: 1 addition & 1 deletion apps/webapp/app/routes/api.v1.deployments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
externalBuildData:
deployment.externalBuildData as InitializeDeploymentResponseBody["externalBuildData"],
imageTag,
registryHost: env.DEPLOY_REGISTRY_HOST,
registryHost: body.data.registryHost ?? env.DEPLOY_REGISTRY_HOST,
};

return json(responseBody, { status: 200 });
Expand Down
8 changes: 7 additions & 1 deletion apps/webapp/app/routes/api.v1.usage.ingest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,13 @@ export async function action({ request }: ActionFunctionArgs) {
}

try {
return await reportComputeUsage(request);
const result = await reportComputeUsage(request);

if (result === undefined) {
return new Response(null, { status: 500 });
}

return result;
} catch (e) {
logger.error("Error reporting compute usage", { error: e });
return new Response(null, { status: 500 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
syncDeclarativeSchedules,
} from "./createBackgroundWorker.server";
import { TimeoutDeploymentService } from "./timeoutDeployment.server";
import { logger } from "~/services/logger.server";

export class CreateDeploymentBackgroundWorkerService extends BaseService {
public async call(
Expand Down
8 changes: 6 additions & 2 deletions apps/webapp/app/v3/services/initializeDeployment.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ export class InitializeDeploymentService extends BaseService {
const nextVersion = calculateNextBuildVersion(latestDeployment?.version);

// Try and create a depot build and get back the external build data
const externalBuildData = await createRemoteImageBuild(environment.project);
const externalBuildData = !!payload.selfHosted
? await createRemoteImageBuild(environment.project)
: undefined;

const triggeredBy = payload.userId
? await this._prisma.user.findUnique({
Expand Down Expand Up @@ -65,7 +67,9 @@ export class InitializeDeploymentService extends BaseService {
new Date(Date.now() + 180_000) // 3 minutes
);

const imageTag = `${env.DEPLOY_REGISTRY_NAMESPACE}/${environment.project.externalRef}:${deployment.version}.${environment.slug}`;
const imageTag = `${payload.namespace ?? env.DEPLOY_REGISTRY_NAMESPACE}/${
environment.project.externalRef
}:${deployment.version}.${environment.slug}`;

return { deployment, imageTag };
});
Expand Down
47 changes: 46 additions & 1 deletion docs/errors-retrying.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ In this complicated example:
- If there are no Response headers we let the normal retrying logic handle it (return undefined).
- If we've run out of requests or tokens we retry at the time specified in the headers.

```ts
<CodeGroup>

```ts tasks.ts
import { task } from "@trigger.dev/sdk/v3";
import { calculateISO8601DurationOpenAIVariantResetAt, openai } from "./openai.js";

export const openaiTask = task({
id: "openai-task",
Expand Down Expand Up @@ -257,6 +260,48 @@ export const openaiTask = task({
});
```

```ts openai.ts
import { OpenAI } from "openai";

export const openai = new OpenAI({ apiKey: env.OPENAI_API_KEY });

export function calculateISO8601DurationOpenAIVariantResetAt(
resets: string,
now: Date = new Date()
): Date | undefined {
// Check if the input is null or undefined
if (!resets) return undefined;

// Regular expression to match the duration string pattern
const pattern = /^(?:(\d+)d)?(?:(\d+)h)?(?:(\d+)m)?(?:(\d+(?:\.\d+)?)s)?(?:(\d+)ms)?$/;
const match = resets.match(pattern);

// If the string doesn't match the expected format, return undefined
if (!match) return undefined;

// Extract days, hours, minutes, seconds, and milliseconds from the string
const days = parseInt(match[1] ?? "0", 10) || 0;
const hours = parseInt(match[2] ?? "0", 10) || 0;
const minutes = parseInt(match[3] ?? "0", 10) || 0;
const seconds = parseFloat(match[4] ?? "0") || 0;
const milliseconds = parseInt(match[5] ?? "0", 10) || 0;

// Calculate the future date based on the current date plus the extracted time
const resetAt = new Date(now);
resetAt.setDate(resetAt.getDate() + days);
resetAt.setHours(resetAt.getHours() + hours);
resetAt.setMinutes(resetAt.getMinutes() + minutes);
resetAt.setSeconds(resetAt.getSeconds() + Math.floor(seconds));
resetAt.setMilliseconds(
resetAt.getMilliseconds() + (seconds - Math.floor(seconds)) * 1000 + milliseconds
);

return resetAt;
}
```

</CodeGroup>

## Preventing retries

### Using `AbortTaskRunError`
Expand Down
17 changes: 17 additions & 0 deletions docs/guides/new-build-system-preview.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,24 @@ You can now authenticate the `dev` command using the `TRIGGER_ACCESS_TOKEN` envi
TRIGGER_ACCESS_TOKEN=<your access token> npx [email protected] dev
```

### Better deploy support for self-hosters

You can now specify a custom registry and namespace when deploying via a self-hosted instance of Trigger.dev:

```sh
npx [email protected] deploy --self-hosted --load-image --push --registry docker.io --namespace mydockerhubusername
```

All you have to do is create a repository in dockerhub that matches the project ref of your Trigger.dev project (e.g. `proj_rrkpdguyagvsoktglnod`)

<Note>
Docker Hub will automatically create a repository the first time you push, which is public by
default. If you want to keep these images private, make sure you create the repository before you
first run the `deploy` command
</Note>

## Known issues

- Path aliases are not yet support in your `trigger.config.ts` file. To workaround this issue you'll need to rewrite path aliases to their relative paths. (See [this](https://github.com/unjs/jiti/issues/166) and [this](https://knip.dev/reference/known-issues#path-aliases-in-config-files)) for more info.
- Some events in the run trace view may get permanently stuck in a loading state. This is a known issue and we're working on a fix.
- `*.test.ts` and `.spec.ts` files inside the trigger dirs will be bundled and could cause issues. You'll need to move these files outside of the trigger dirs to avoid this issue.
3 changes: 2 additions & 1 deletion packages/build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
"dependencies": {
"@trigger.dev/core": "workspace:3.0.0-beta.56",
"pkg-types": "^1.1.3",
"tinyglobby": "^0.2.2"
"tinyglobby": "^0.2.2",
"tsconfck": "3.1.3"
},
"devDependencies": {
"@types/node": "20.14.14",
Expand Down
47 changes: 42 additions & 5 deletions packages/build/src/extensions/prisma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export type PrismaExtensionOptions = {
schema: string;
migrate?: boolean;
version?: string;
/**
* Adds the `--sql` flag to the `prisma generate` command. This will generate the SQL files for the Prisma schema. Requires the `typedSql preview feature and prisma 5.19.0 or later.
*/
typedSql?: boolean;
/**
* The client generator to use. Set this param to prevent all generators in the prisma schema from being generated.
*
Expand Down Expand Up @@ -114,9 +118,40 @@ export class PrismaExtension implements BuildExtension {

let prismaDir: string | undefined;

const generatorFlag = this.options.clientGenerator
? `--generator=${this.options.clientGenerator}`
: "";
const generatorFlags: string[] = [];

if (this.options.clientGenerator) {
generatorFlags.push(`--generator=${this.options.clientGenerator}`);
}

if (this.options.typedSql) {
generatorFlags.push(`--sql`);

const schemaDir = dirname(this._resolvedSchemaPath);
const prismaDir = dirname(schemaDir);

context.logger.debug(`Using typedSql`);

// Find all the files prisma/sql/*.sql
const sqlFiles = await readdir(join(prismaDir, "sql")).then((files) =>
files.filter((file) => file.endsWith(".sql"))
);

context.logger.debug(`Found sql files`, {
sqlFiles,
});

const sqlDestinationPath = join(manifest.outputPath, "prisma", "sql");

for (const file of sqlFiles) {
const destination = join(sqlDestinationPath, file);
const source = join(prismaDir, "sql", file);

context.logger.debug(`Copying the sql from ${source} to ${destination}`);

await cp(source, destination);
}
}

if (usingSchemaFolder) {
const schemaDir = dirname(this._resolvedSchemaPath);
Expand Down Expand Up @@ -150,7 +185,7 @@ export class PrismaExtension implements BuildExtension {
commands.push(
`${binaryForRuntime(
manifest.runtime
)} node_modules/prisma/build/index.js generate ${generatorFlag}` // Don't add the --schema flag or this will fail
)} node_modules/prisma/build/index.js generate ${generatorFlags.join(" ")}` // Don't add the --schema flag or this will fail
);
} else {
prismaDir = dirname(this._resolvedSchemaPath);
Expand All @@ -169,7 +204,9 @@ export class PrismaExtension implements BuildExtension {
commands.push(
`${binaryForRuntime(
manifest.runtime
)} node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma ${generatorFlag}`
)} node_modules/prisma/build/index.js generate --schema=./prisma/schema.prisma ${generatorFlags.join(
" "
)}`
);
}

Expand Down
Loading
Loading