-
-
Notifications
You must be signed in to change notification settings - Fork 886
presets(vercel): integrate with scheduled tasks #4030
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
49b07c4
703ae6d
cd0ca19
237dfd6
30b595b
3bcc196
7b1afca
68042b8
9e7e37c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { H3, HTTPError } from "h3"; | ||
| import { runCronTasks } from "#nitro/runtime/task"; | ||
|
|
||
| export default new H3().get("/_nitro/tasks/vercel", async (event) => { | ||
|
pi0 marked this conversation as resolved.
Outdated
|
||
| // Validate CRON_SECRET if set - https://vercel.com/docs/cron-jobs/manage-cron-jobs#securing-cron-jobs | ||
| const cronSecret = process.env.CRON_SECRET; | ||
| if (cronSecret) { | ||
| const authHeader = event.req.headers.get("authorization"); | ||
| if (authHeader !== `Bearer ${cronSecret}`) { | ||
|
RihanArfan marked this conversation as resolved.
Outdated
|
||
| throw new HTTPError("Unauthorized", { status: 401 }); | ||
| } | ||
| } | ||
|
|
||
| const cron = event.req.headers.get("x-vercel-cron-schedule"); | ||
| if (!cron) { | ||
| throw new HTTPError("Missing x-vercel-cron-schedule header", { status: 400 }); | ||
| } | ||
|
RihanArfan marked this conversation as resolved.
|
||
|
|
||
| const result = await runCronTasks(cron, { | ||
| context: {}, | ||
| payload: { | ||
| scheduledTime: Date.now(), | ||
| }, | ||
| }); | ||
|
|
||
| return { cron, tasks: result }; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this object consumed by vercel? Why this specific shape?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No particular reason. I've double checked and Vercel only shows things that were logged but not the response of this endpoint, so I'll update it so we return nothing. Should we log anything? Like Running cron schedule * * * * *
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We mighjt like success: true for example. My main concern is to not introduce a reponse and break it later only
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorted |
||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.