Compare commits

..

3 Commits

Author SHA1 Message Date
javayhu
13bada6a64 chore: add hello world task 2025-06-23 01:03:11 +08:00
javayhu
57fa9a0136 chore: add cursor rules for trigger 2025-06-23 01:02:57 +08:00
javayhu
d9e076ed8b feat: add trigger 2025-06-22 14:21:47 +08:00
9 changed files with 2304 additions and 4 deletions

File diff suppressed because it is too large Load Diff

3
.gitignore vendored
View File

@ -46,6 +46,9 @@ next-env.d.ts
# fumadocs
.source
# trigger
.trigger
# OpenNext build output
.open-next

View File

@ -7,6 +7,7 @@
"build": "next build",
"start": "next start",
"postinstall": "fumadocs-mdx",
"trigger:dev": "npx trigger.dev@latest dev",
"lint": "biome check --write .",
"lint:fix": "biome check --fix --unsafe .",
"format": "biome format --write .",
@ -70,6 +71,7 @@
"@stripe/stripe-js": "^5.6.0",
"@tabler/icons-react": "^3.31.0",
"@tanstack/react-table": "^8.21.2",
"@trigger.dev/sdk": "^3.3.17",
"@types/canvas-confetti": "^1.9.0",
"@vercel/analytics": "^1.5.0",
"@vercel/speed-insights": "^1.2.0",
@ -127,6 +129,7 @@
"devDependencies": {
"@biomejs/biome": "1.9.4",
"@tailwindcss/postcss": "^4.0.14",
"@trigger.dev/build": "^3.3.17",
"@types/mdx": "^2.0.13",
"@types/node": "^20.19.0",
"@types/pg": "^8.11.11",
@ -139,5 +142,6 @@
"tailwindcss": "^4.0.14",
"tsx": "^4.19.3",
"typescript": "^5.8.3"
}
},
"packageManager": "pnpm@10.12.1+sha512.f0dda8580f0ee9481c5c79a1d927b9164f2c478e90992ad268bbb2465a736984391d6333d2c327913578b2804af33474ca554ba29c04a8b13060a717675ae3ac"
}

939
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View 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
View 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);
},
});

View 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
View 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"],
});

View File

@ -24,6 +24,12 @@
"@/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"]
}