[▲ Vercel Community](/) · [Categories](/categories) · [Latest](/latest) · [Top](/top) · [Live](/live) [Help](/c/help/9) # Cron Job Not Running 339 views · 6 likes · 17 posts For Ry In Range (@for-ry-in-range) · 2024-08-19 Hi, I am attempting to create a cron job. The cron job I created correctly shows up on my Vercel dashboard. But the cron job does not run at the scheduled time. Instead, it only runs once I start building a new build. That probably sounds weird, but I've tried four times and every time the cron job does not run until I start a new build. This is my vercel.json file: { "crons": [{ "path": "/api/cron", "schedule": "35 4 *" }] } Amy Egan (@amyegan) · 2024-08-19 Hi @for-ry-in-range. It looks like there might be a problem with your cron schedule. You can use a tool [crontab guru](https://crontab.guru/) to validate your cron expression. For Ry In Range (@for-ry-in-range) · 2024-08-20 @amyegan I had already used the crontab guru to validate the time. Also, I know the cron job can run within a one hour window of the time given. I've waited for the whole hour and the cron job does not run, until I start a new build. What else do you recommend I try? For Ry In Range (@for-ry-in-range) · 2024-08-20 @amyegan Oh I just realized my `schedule` was missing "* *", which is why you thought there was a problem with the cron schedule. I think I accidentally deleted part of the code after I pasted it into the forum. But my actual code is "35 4 * * *" :smiley: Amy Egan (@amyegan) · 2024-08-20 That schedule makes more sense! If you try to run the `/api/cron` function directly and then try to click the **Run** button in project settings to manually run the cron job. What happens in each of those scenarios? For Ry In Range (@for-ry-in-range) · 2024-08-20 When I run /api/cron in Postman, nothing happens. And when I click the Run button, the log shows status=200. But the code in /api/cron still did not run. So then I tried starting a new build, and then the /api/cron finally ran. Amy Egan (@amyegan) · 2024-08-20 It seems like there's a problem with the function itself if nothing happens when you run it with Postman or the Run button. I recommend looking into what's going wrong with the function. The [Deployment Summary](https://vercel.com/docs/deployments/overview#deployment-summary) will tell you more about the functions that were deployed. And [Runtime Logs](https://vercel.com/docs/observability/runtime-logs#runtime-logs) can help you get more details about what happens when the function is called. You can also check the deployment output For Ry In Range (@for-ry-in-range) · 2024-08-20 The /api/cron function does correctly show up in the Deployment Summary. The Runtime Logs show that the GET request to /api/cron went through successfully for BOTH the call from Postman and the call from the Run button, even though the code in /api/cron did not run. What else should I try? Thanks! Amy Egan (@amyegan) · 2024-08-20 Since the functions at least *attempt* to do something, I suspect there's a silent error or a flaw in the return data. Using [try/catch](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch) and [console.log()](https://developer.mozilla.org/en-US/docs/Web/API/console/log_static) is probably the simplest way to gather more info about what's happening inside the function. For Ry In Range (@for-ry-in-range) · 2024-08-20 ``` import { inngest } from "../../../../inngest/client"; export async function GET() { try { await inngest.send({ name: "myfunc/send-summary" }); console.log("Cron worked") return new Response("Successful!", { status: 200 }); } catch (error) { console.error("Error:", error) return new Response("Error occured", {status: 500}) } } ``` This is my code at /api/cron. I have a console.log() and console.error() but nothing is printing. It would print to the Logs tab, right? For Ry In Range (@for-ry-in-range) · 2024-08-21 Hi, @amyegan are you still there? Amy Egan (@amyegan) · 2024-08-21 Yes, you should see it in the Logs tab for the deployment. Do you see any errors, even ones that seem unrelated, in the Logs tab? What happens if you put a `console.log()` *before* `await inngest...` or even before the try/catch statement? For Ry In Range (@for-ry-in-range) · 2024-08-21  @amyegan I put the console.log() before the try/catch statement and I still didn't get anything in the Logs tab. This is what I see in the Logs tab. Amy Egan (@amyegan) · 2024-08-21 Please check your [middleware](https://vercel.com/docs/functions/edge-middleware). It's possible that something there is preventing the function from working as you expect. Note that you can click the log row to expand a panel with more details, which would include the `console.log()` output if available. For Ry In Range (@for-ry-in-range) · 2024-08-22 @amyegan I don't see anything printing when I expand the panel:  This is my middleware.ts: ``` import { clerkMiddleware } from "@clerk/nextjs/server"; export default clerkMiddleware(); export const config = { matcher: ['/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico|csv|docx?|xlsx?|zip|webmanifest)).*)', '/(api|trpc)(.*)', '/app/api/get_inboxes(.*)', '/app/api/cron(.*)'], }; ``` Is there anything wrong with it? Sebastian (@webmonkey) · 2024-08-22 · ♥ 3 Hey @for-ry-in-range , Most likely the logs won't show up since the function you're executing through your cronjob is cached. The cron job will always run according to it's schedule, but if it hits an endpoint that's cached then it won't show. Cron jobs don't have the ability to completely bypass the platform/code caching and instead are just treated as a normal request. The underlying function is generated during build, so the Cron Job cannot bypass the settings defined (or not, so default caching behavior) when executing the function. This caching behaviour can be prevented by adding the following to your API route `/api/cron` ([see docs](https://nextjs.org/docs/app/api-reference/file-conventions/route-segment-config#dynamic)): `export const dynamic = 'force-dynamic'` Can you give this a try and let us know if it works? For Ry In Range (@for-ry-in-range) · 2024-08-22 · ♥ 3 It works now after adding `export const dynamic = 'force-dynamic'` Thank you so much for your help!