Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
44d62ee
Initial attempt at ESM version of core-backend
ericallam Dec 1, 2023
8332823
Use modern esm output
ericallam Dec 1, 2023
2276b46
patch tsup to stop converting node: imports
ericallam Dec 1, 2023
bfc4b86
upgrade @trigger.dev/sdk to esm and add hono framework
ericallam Dec 1, 2023
c839b08
Check for .dev.vars in hono
ericallam Dec 1, 2023
3125188
Add addMiddleware which works for workers
ericallam Dec 1, 2023
73f4a18
Correctly type addMiddleware
ericallam Dec 1, 2023
1a2a305
Use node:crypto instead of crypto
ericallam Dec 1, 2023
cc180d2
Import from crypto for the types
ericallam Dec 1, 2023
89723e8
Explicitly import node process
ericallam Dec 1, 2023
315fe34
Explicilty import node buffer
ericallam Dec 1, 2023
2008432
Fixed broken type import
ericallam Dec 1, 2023
a665f44
cache: option not implemented in CF workers
ericallam Dec 1, 2023
e10e4a0
Check for the cache key support correctly
ericallam Dec 1, 2023
7bc37a9
ESM version of integration-kit
ericallam Dec 4, 2023
6445852
Upgrade OpenAI package
ericallam Dec 4, 2023
c87df15
Remove the file stuff from integration kit
ericallam Dec 4, 2023
87c0031
Upgrade linear and create a script to do the upgrading
ericallam Dec 4, 2023
49da849
Upgrade Stripe
ericallam Dec 4, 2023
9f9a321
Upgrade resend
ericallam Dec 4, 2023
36118b5
Upgrade replicate
ericallam Dec 4, 2023
d647803
Upgrade airtable
ericallam Dec 4, 2023
1a3300f
Upgrade github
ericallam Dec 4, 2023
b0648ea
Upgrade slack
ericallam Dec 4, 2023
533f390
Upgrade supabase
ericallam Dec 4, 2023
4131d07
Missing a bunch of node:buffer imports
ericallam Dec 4, 2023
6a5188e
Upgrade shopify
ericallam Dec 4, 2023
af3ed5a
Upgrade sendgrid
ericallam Dec 4, 2023
84a93d3
Upgrade typeform
ericallam Dec 4, 2023
47d0839
Upgrade plain
ericallam Dec 4, 2023
939afab
Upgrade sveltekit
ericallam Dec 4, 2023
b00fd17
Fixed typeform
ericallam Dec 4, 2023
3da7c61
Upgrade nextjs
ericallam Dec 4, 2023
9cba444
Use new NextResponse instead of NextResponse.json
ericallam Dec 4, 2023
931e0b3
Try and use Response instead of NextResponse
ericallam Dec 4, 2023
b710e4b
Upgrade remix
ericallam Dec 4, 2023
42b5f02
Upgrade express
ericallam Dec 5, 2023
fe24143
Upgrade testing
ericallam Dec 5, 2023
1087c87
Upgrade nest.js
ericallam Dec 5, 2023
a6286c2
Adding runtime tests to make sure the SDK works across all supported …
ericallam Dec 5, 2023
764752b
Install deno and bun in the unit test workflow
ericallam Dec 5, 2023
c23be58
Update changesets
ericallam Dec 5, 2023
c7ddc4e
Update supabase to use supabase-management-js 1.0.0
ericallam Dec 5, 2023
cae65ab
Resolved the lock file
ericallam Dec 5, 2023
091c1ad
Add deno tests
ericallam Dec 5, 2023
517a2ab
Add hono docs and separate job creation from attachment
ericallam Dec 5, 2023
9d72963
Fixed test failure
ericallam Dec 5, 2023
3b17222
Actually fix the tests this time
ericallam Dec 5, 2023
b62931b
Add note about enabling node.js compat
ericallam Dec 5, 2023
073930f
Correctly identify cloudflare timeouts
ericallam Dec 5, 2023
2c1958a
Correctly handle deno deploy timeouts
ericallam Dec 6, 2023
d0b045c
Update hono CLI docs
ericallam Dec 6, 2023
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
29 changes: 29 additions & 0 deletions .changeset/ninety-boats-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
---
"@trigger.dev/integration-kit": minor
"@trigger.dev/replicate": minor
"@trigger.dev/airtable": minor
"@trigger.dev/sendgrid": minor
"@trigger.dev/supabase": minor
"@trigger.dev/typeform": minor
"@trigger.dev/core-backend": minor
"@trigger.dev/shopify": minor
"@trigger.dev/sdk": minor
"@trigger.dev/github": minor
"@trigger.dev/linear": minor
"@trigger.dev/openai": minor
"@trigger.dev/resend": minor
"@trigger.dev/stripe": minor
"@trigger.dev/plain": minor
"@trigger.dev/slack": minor
"@trigger.dev/sveltekit": minor
"@trigger.dev/express": minor
"@trigger.dev/testing": minor
"@trigger.dev/nestjs": minor
"@trigger.dev/nextjs": minor
"@trigger.dev/remix": minor
"@trigger.dev/core": minor
---

Support for Deno, Bun and Cloudflare workers, as well as conditionally exporting ESM versions of the package instead of just commonjs.

Cloudflare worker support requires the node compat flag turned on (https://developers.cloudflare.com/workers/runtime-apis/nodejs/)
6 changes: 6 additions & 0 deletions .changeset/shaggy-crabs-sneeze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@trigger.dev/hono": patch
"@trigger.dev/cli": patch
---

Added hono framework support
10 changes: 10 additions & 0 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@ jobs:
node-version: 18
cache: "pnpm"

- name: ⎔ Setup Deno
uses: denoland/setup-deno@v1
with:
deno-version: v1.x

- name: ⎔ Setup bun
uses: oven-sh/setup-bun@v1
with:
bun-version: "1.0.15"

- name: 📥 Download deps
run: pnpm install --frozen-lockfile

Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"deno.enablePaths": ["references/deno-reference"],
"deno.enablePaths": ["references/deno-reference", "runtime_tests/tests/deno"],
"debug.toolBarLocation": "commandCenter"
}
2 changes: 1 addition & 1 deletion apps/webapp/app/components/run/RunOverview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export function RunOverview({ run, trigger, showRerun, paths }: RunOverviewProps
<PageInfoProperty
icon={"list-numbers"}
label={"Execution Count"}
value={run.executionCount}
value={<>{run.executionCount}</>}
/>
</PageInfoGroup>
<PageInfoGroup alignment="right">
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/app/consts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export const EXECUTE_JOB_RETRY_LIMIT = 10;
export const MAX_RUN_YIELDED_EXECUTIONS = 100;
export const RUN_CHUNK_EXECUTION_BUFFER = 350;
export const MAX_RUN_CHUNK_EXECUTION_LIMIT = 120000; // 2 minutes
export const RESPONSE_TIMEOUT_STATUS_CODES = [408, 504];
export const VERCEL_RESPONSE_TIMEOUT_STATUS_CODES = [408, 504];
26 changes: 23 additions & 3 deletions apps/webapp/app/models/endpoint.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RESPONSE_TIMEOUT_STATUS_CODES } from "~/consts";
import { VERCEL_RESPONSE_TIMEOUT_STATUS_CODES } from "~/consts";
import { prisma } from "~/db.server";
import { Prettify } from "~/lib.es5";

Expand All @@ -20,13 +20,33 @@ export async function findEndpoint(id: string) {
});
}

export function detectResponseIsTimeout(response?: Response) {
export function detectResponseIsTimeout(rawBody: string, response?: Response) {
if (!response) {
return false;
}

return (
RESPONSE_TIMEOUT_STATUS_CODES.includes(response.status) ||
isResponseVercelTimeout(response) ||
isResponseDenoDeployTimeout(rawBody, response) ||
isResponseCloudflareTimeout(rawBody, response)
);
}

function isResponseCloudflareTimeout(rawBody: string, response: Response) {
return (
response.status === 503 &&
rawBody.includes("Worker exceeded resource limits") &&
typeof response.headers.get("cf-ray") === "string"
);
}

function isResponseVercelTimeout(response: Response) {
return (
VERCEL_RESPONSE_TIMEOUT_STATUS_CODES.includes(response.status) ||
response.headers.get("x-vercel-error") === "FUNCTION_INVOCATION_TIMEOUT"
);
}

function isResponseDenoDeployTimeout(rawBody: string, response: Response) {
return response.status === 502 && rawBody.includes("TIME_LIMIT");
}
1 change: 1 addition & 0 deletions apps/webapp/app/services/endpointApi.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ function addStandardRequestOptions(options: RequestInit) {
...options.headers,
"user-agent": "triggerdotdev-server/2.0.0",
"x-trigger-version": API_VERSIONS.LAZY_LOADED_CACHED_TASKS,
accept: "application/json",
},
};
}
6 changes: 4 additions & 2 deletions apps/webapp/app/services/endpoints/probeEndpoint.server.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { MAX_RUN_CHUNK_EXECUTION_LIMIT, RESPONSE_TIMEOUT_STATUS_CODES } from "~/consts";
import { MAX_RUN_CHUNK_EXECUTION_LIMIT } from "~/consts";
import { prisma, PrismaClient } from "~/db.server";
import { EndpointApi } from "../endpointApi.server";
import { logger } from "../logger.server";
Expand Down Expand Up @@ -46,8 +46,10 @@ export class ProbeEndpointService {
},
});

const rawBody = await response.text();

// If the response is a 200, or it was a timeout, we can assume the endpoint is up and update the runChunkExecutionLimit
if (response.status === 200 || detectResponseIsTimeout(response)) {
if (response.status === 200 || detectResponseIsTimeout(rawBody, response)) {
await this.#prismaClient.endpoint.update({
where: {
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const supabase = new SupabaseManagement({
id: "__SLUG__",
});

new Job(client, {
client.defineJob({
id: "on-new-todos",
name: "On New Todos",
version: "0.1.1",
Expand All @@ -32,7 +32,7 @@ const supabase = new SupabaseManagement({
apiKey: process.env.SUPABASE_API_KEY!,
});

new Job(client, {
client.defineJob({
id: "on-new-todos",
name: "On New Todos",
version: "0.1.1",
Expand Down Expand Up @@ -136,7 +136,7 @@ const supabase = new Supabase<Database>({
supabaseKey: process.env.SUPABASE_API_KEY!,
});

new Job(client, {
client.defineJob({
id: "on-new-users",
name: "On New Users",
version: "0.1.1",
Expand Down
50 changes: 40 additions & 10 deletions apps/webapp/app/services/runs/performRunExecutionV3.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ export class PerformRunExecutionV3Service {
forceYieldCoordinator.deregisterRun(run.id);

if (!response) {
return await this.#failRunExecutionWithRetry(run, input.lastAttempt, {
message: `Connection could not be established to the endpoint (${run.endpoint.url})`,
});
return await this.#failRunExecutionWithRetry(
run,
input.lastAttempt,
{
message: `Connection could not be established to the endpoint (${run.endpoint.url})`,
},
durationInMs
);
}

// Update the endpoint version if it has changed
Expand Down Expand Up @@ -285,6 +290,8 @@ export class PerformRunExecutionV3Service {
status: response.status,
runId: run.id,
endpoint: run.endpoint.url,
headers: rawHeaders,
rawBody,
});

const errorBody = safeJsonZodParse(errorParser, rawBody);
Expand All @@ -294,7 +301,12 @@ export class PerformRunExecutionV3Service {
if (response.status >= 400 && response.status <= 499) {
return await this.#failRunExecution(this.#prismaClient, run, errorBody.data);
} else {
return await this.#failRunExecutionWithRetry(run, input.lastAttempt, errorBody.data);
return await this.#failRunExecutionWithRetry(
run,
input.lastAttempt,
errorBody.data,
durationInMs
);
}
}

Expand All @@ -311,17 +323,22 @@ export class PerformRunExecutionV3Service {
);
} else {
// If the error is a timeout, we should mark this execution as succeeded (by not throwing an error) and enqueue a new execution
if (detectResponseIsTimeout(response)) {
if (detectResponseIsTimeout(rawBody, response)) {
return await this.#resumeRunExecutionAfterTimeout(
this.#prismaClient,
run,
input,
durationInMs
);
} else {
return await this.#failRunExecutionWithRetry(run, input.lastAttempt, {
message: `Endpoint responded with ${response.status} status code`,
});
return await this.#failRunExecutionWithRetry(
run,
input.lastAttempt,
{
message: `Endpoint responded with ${response.status} status code`,
},
durationInMs
);
}
}
}
Expand Down Expand Up @@ -996,6 +1013,9 @@ export class PerformRunExecutionV3Service {
executionDuration: {
increment: durationInMs,
},
executionCount: {
increment: 1,
},
endpoint: {
update: {
// Never allow the execution limit to be less than 10 seconds or more than MAX_RUN_CHUNK_EXECUTION_LIMIT
Expand All @@ -1018,7 +1038,8 @@ export class PerformRunExecutionV3Service {
async #failRunExecutionWithRetry(
run: FoundRun,
lastAttempt: boolean,
output: Record<string, any>
output: Record<string, any>,
durationInMs: number = 0
): Promise<void> {
if (lastAttempt) {
return await this.#failRunExecution(this.#prismaClient, run, output);
Expand All @@ -1028,10 +1049,16 @@ export class PerformRunExecutionV3Service {
where: { id: run.id },
data: {
status: "WAITING_TO_EXECUTE",
executionDuration: {
increment: durationInMs,
},
executionCount: {
increment: 1,
},
},
});

throw new Error(JSON.stringify(output));
await ResumeRunService.enqueue(run, this.#prismaClient);
}

async #failRunExecution(
Expand All @@ -1052,6 +1079,9 @@ export class PerformRunExecutionV3Service {
executionDuration: {
increment: durationInMs,
},
executionCount: {
increment: 1,
},
tasks: {
updateMany: {
where: {
Expand Down
36 changes: 27 additions & 9 deletions config-packages/tsconfig/integration.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,37 @@
{
"extends": "./node18.json",
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2019"],
"lib": [
"DOM",
"DOM.Iterable",
"ES2019"
],
"paths": {
"@trigger.dev/tsup/*": ["../../config-packages/tsup/src/*"],
"@trigger.dev/tsup": ["../../config-packages/tsup/src/index"],
"@trigger.dev/sdk/*": ["../../packages/trigger-sdk/src/*"],
"@trigger.dev/sdk": ["../../packages/trigger-sdk/src/index"],
"@trigger.dev/integration-kit/*": ["../../packages/integration-kit/src/*"],
"@trigger.dev/integration-kit": ["../../packages/integration-kit/src/index"]
"@trigger.dev/tsup/*": [
"../../config-packages/tsup/src/*"
],
"@trigger.dev/tsup": [
"../../config-packages/tsup/src/index"
],
"@trigger.dev/sdk/*": [
"../../packages/trigger-sdk/src/*"
],
"@trigger.dev/sdk": [
"../../packages/trigger-sdk/src/index"
],
"@trigger.dev/integration-kit/*": [
"../../packages/integration-kit/src/*"
],
"@trigger.dev/integration-kit": [
"../../packages/integration-kit/src/index"
]
},
"declaration": false,
"declarationMap": false,
"baseUrl": ".",
"stripInternal": true
},
"exclude": ["node_modules"]
}
"exclude": [
"node_modules"
]
}
14 changes: 12 additions & 2 deletions config-packages/tsup/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
"version": "0.0.0",
"private": true,
"license": "MIT",
"main": "./src/index.ts",
"types": "./src/index.ts",
"dependencies": {
"esbuild": "^0.19.2",
"tsup": "^8.0.1"
},
"devDependencies": {
"tsup": "7.1.x"
"@types/node": "18",
"typescript": "^5.3.0"
},
"engines": {
"node": ">=18.0.0"
}
}
}
1 change: 1 addition & 0 deletions config-packages/tsup/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { defineConfig } from "tsup";
export { deepMergeOptions } from "./utils";
export { options as integrationOptions } from "./integration";
export { options as packageOptions, defineConfig as defineConfigPackage } from "./package";
39 changes: 39 additions & 0 deletions config-packages/tsup/src/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { Plugin } from "esbuild";
import { Options, defineConfig as defineConfigTSUP } from "tsup";

const restoreNodeProtocolPlugin = (): Plugin => {
return {
name: "node-protocol-plugin-restorer",
setup(build) {
build.onResolve(
{
filter: /node:/,
},
async (args) => {
return { path: args.path, external: true };
}
);
},
};
};

export const options: Options = {
name: "main",
config: "tsconfig.json",
entry: ["./src/index.ts"],
outDir: "./dist",
platform: "node",
format: ["cjs", "esm"],
legacyOutput: false,
sourcemap: true,
clean: true,
bundle: true,
splitting: false,
dts: true,
treeshake: {
preset: "recommended",
},
esbuildPlugins: [restoreNodeProtocolPlugin()],
};

export const defineConfig = defineConfigTSUP(options);
Loading