feat: add trigger
This commit is contained in:
parent
cfbfa409b0
commit
d9e076ed8b
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
|
||||||
|
|
||||||
|
@ -70,6 +70,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 +128,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 +141,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
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);
|
||||||
|
},
|
||||||
|
});
|
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