Compare commits
3 Commits
cloudflare
...
dev/trigge
Author | SHA1 | Date | |
---|---|---|---|
|
13bada6a64 | ||
|
57fa9a0136 | ||
|
d9e076ed8b |
1269
.cursor/rules/trigger-writing-tasks.mdc
Normal file
1269
.cursor/rules/trigger-writing-tasks.mdc
Normal file
File diff suppressed because it is too large
Load Diff
3
.gitignore
vendored
3
.gitignore
vendored
@ -46,6 +46,9 @@ next-env.d.ts
|
|||||||
# fumadocs
|
# fumadocs
|
||||||
.source
|
.source
|
||||||
|
|
||||||
|
# trigger
|
||||||
|
.trigger
|
||||||
|
|
||||||
# OpenNext build output
|
# OpenNext build output
|
||||||
.open-next
|
.open-next
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
"build": "next build",
|
"build": "next build",
|
||||||
"start": "next start",
|
"start": "next start",
|
||||||
"postinstall": "fumadocs-mdx",
|
"postinstall": "fumadocs-mdx",
|
||||||
|
"trigger:dev": "npx trigger.dev@latest dev",
|
||||||
"lint": "biome check --write .",
|
"lint": "biome check --write .",
|
||||||
"lint:fix": "biome check --fix --unsafe .",
|
"lint:fix": "biome check --fix --unsafe .",
|
||||||
"format": "biome format --write .",
|
"format": "biome format --write .",
|
||||||
@ -70,6 +71,7 @@
|
|||||||
"@stripe/stripe-js": "^5.6.0",
|
"@stripe/stripe-js": "^5.6.0",
|
||||||
"@tabler/icons-react": "^3.31.0",
|
"@tabler/icons-react": "^3.31.0",
|
||||||
"@tanstack/react-table": "^8.21.2",
|
"@tanstack/react-table": "^8.21.2",
|
||||||
|
"@trigger.dev/sdk": "^3.3.17",
|
||||||
"@types/canvas-confetti": "^1.9.0",
|
"@types/canvas-confetti": "^1.9.0",
|
||||||
"@vercel/analytics": "^1.5.0",
|
"@vercel/analytics": "^1.5.0",
|
||||||
"@vercel/speed-insights": "^1.2.0",
|
"@vercel/speed-insights": "^1.2.0",
|
||||||
@ -127,6 +129,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "1.9.4",
|
"@biomejs/biome": "1.9.4",
|
||||||
"@tailwindcss/postcss": "^4.0.14",
|
"@tailwindcss/postcss": "^4.0.14",
|
||||||
|
"@trigger.dev/build": "^3.3.17",
|
||||||
"@types/mdx": "^2.0.13",
|
"@types/mdx": "^2.0.13",
|
||||||
"@types/node": "^20.19.0",
|
"@types/node": "^20.19.0",
|
||||||
"@types/pg": "^8.11.11",
|
"@types/pg": "^8.11.11",
|
||||||
@ -139,5 +142,6 @@
|
|||||||
"tailwindcss": "^4.0.14",
|
"tailwindcss": "^4.0.14",
|
||||||
"tsx": "^4.19.3",
|
"tsx": "^4.19.3",
|
||||||
"typescript": "^5.8.3"
|
"typescript": "^5.8.3"
|
||||||
}
|
},
|
||||||
|
"packageManager": "pnpm@10.12.1+sha512.f0dda8580f0ee9481c5c79a1d927b9164f2c478e90992ad268bbb2465a736984391d6333d2c327913578b2804af33474ca554ba29c04a8b13060a717675ae3ac"
|
||||||
}
|
}
|
||||||
|
939
pnpm-lock.yaml
generated
939
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
20
src/actions/hello-world-task.ts
Normal file
20
src/actions/hello-world-task.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
'use server';
|
||||||
|
|
||||||
|
import type { helloWorldTask } from '@/trigger/hello-world';
|
||||||
|
import { tasks } from '@trigger.dev/sdk/v3';
|
||||||
|
|
||||||
|
export async function myTask() {
|
||||||
|
try {
|
||||||
|
const handle = await tasks.trigger<typeof helloWorldTask>(
|
||||||
|
'hello-world',
|
||||||
|
'James'
|
||||||
|
);
|
||||||
|
|
||||||
|
return { handle };
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return {
|
||||||
|
error: 'something went wrong',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
27
src/trigger/example.ts
Normal file
27
src/trigger/example.ts
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import { logger, schedules, wait } from "@trigger.dev/sdk/v3";
|
||||||
|
|
||||||
|
export const firstScheduledTask = schedules.task({
|
||||||
|
id: "first-scheduled-task",
|
||||||
|
// Every hour
|
||||||
|
cron: "0 * * * *",
|
||||||
|
// Set an optional maxDuration to prevent tasks from running indefinitely
|
||||||
|
maxDuration: 300, // Stop executing after 300 secs (5 mins) of compute
|
||||||
|
run: async (payload, { ctx }) => {
|
||||||
|
// The payload contains the last run timestamp that you can use to check if this is the first run
|
||||||
|
// And calculate the time since the last run
|
||||||
|
const distanceInMs =
|
||||||
|
payload.timestamp.getTime() - (payload.lastTimestamp ?? new Date()).getTime();
|
||||||
|
|
||||||
|
logger.log("First scheduled tasks", { payload, distanceInMs });
|
||||||
|
|
||||||
|
// Wait for 5 seconds
|
||||||
|
await wait.for({ seconds: 5 });
|
||||||
|
|
||||||
|
// Format the timestamp using the timezone from the payload
|
||||||
|
const formatted = payload.timestamp.toLocaleString("en-US", {
|
||||||
|
timeZone: payload.timezone,
|
||||||
|
});
|
||||||
|
|
||||||
|
logger.log(formatted);
|
||||||
|
},
|
||||||
|
});
|
14
src/trigger/hello-world.ts
Normal file
14
src/trigger/hello-world.ts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
import { logger, task, wait } from '@trigger.dev/sdk/v3';
|
||||||
|
|
||||||
|
export const helloWorldTask = task({
|
||||||
|
id: 'hello-world',
|
||||||
|
run: async (payload: any, { ctx }) => {
|
||||||
|
logger.log('Hello, world!', { payload, ctx });
|
||||||
|
|
||||||
|
await wait.for({ seconds: 5 });
|
||||||
|
|
||||||
|
return {
|
||||||
|
message: 'Hello, world!',
|
||||||
|
};
|
||||||
|
},
|
||||||
|
});
|
22
trigger.config.ts
Normal file
22
trigger.config.ts
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import { defineConfig } from "@trigger.dev/sdk/v3";
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
project: "proj_ptscltjuahzcfezzggbn",
|
||||||
|
runtime: "node",
|
||||||
|
logLevel: "log",
|
||||||
|
// The max compute seconds a task is allowed to run. If the task run exceeds this duration, it will be stopped.
|
||||||
|
// You can override this on an individual task.
|
||||||
|
// See https://trigger.dev/docs/runs/max-duration
|
||||||
|
maxDuration: 3600,
|
||||||
|
retries: {
|
||||||
|
enabledInDev: true,
|
||||||
|
default: {
|
||||||
|
maxAttempts: 3,
|
||||||
|
minTimeoutInMs: 1000,
|
||||||
|
maxTimeoutInMs: 10000,
|
||||||
|
factor: 2,
|
||||||
|
randomize: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
dirs: ["./src/trigger"],
|
||||||
|
});
|
@ -24,6 +24,12 @@
|
|||||||
"@/public/*": ["./public/*"]
|
"@/public/*": ["./public/*"]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
"include": [
|
||||||
|
"next-env.d.ts",
|
||||||
|
"**/*.ts",
|
||||||
|
"**/*.tsx",
|
||||||
|
".next/types/**/*.ts",
|
||||||
|
"trigger.config.ts"
|
||||||
|
],
|
||||||
"exclude": ["node_modules"]
|
"exclude": ["node_modules"]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user