Cron Job not executing

I have a cron job that should run every hour. For some reason it never executes.

The code itself is the daily messages route. This is what the folder structure looks like after deployment:

My Deployment is in production - since this is important for cron jobs:
image

I am on the pro plan so there should be no issues about executing at the right time

I can reach the endpoint from both localhost and the deployed url
/dailyMessages
http://localhost:3000/dailyMessages

The expected behavior is that it should send me an email to my email address
I see the expected behavior when I trigger it from localhost, but I DO NOT get the same behavior when I trigger the endpoint on the live site aka /dailyMessages

Domain:
I do not have custom domain and I am just using the domain assigned by Vercel

Cron Job Execution:
-When I deploy the code, I see the expected output in the deploy logs and I DO receive the email

But my cron job never executes after that, it is supposed to be set to run every hour, but it never does.
When I click on Run in the Vercel Dashboard, it also never executes and I do not see anything in runtime logs

vercel.json:

{
    "crons": [
        {
            "path": "/dailyMessages",
            "schedule": "0 * * * *"
        }
    ]
}

I am wondering if the issue could also has to do with what my route returns, this is what the route code looks like:

export async function GET(req: NextRequest) {
    console.log("dailyMessages endpoint called at: ", new Date().valueOf());
    const rowsAffected = await checkTimestampsAndSendMessages();
    return NextResponse.json({ msg: "dailyMessageTrigger", rowsAffected: rowsAffected })
}

This is what the build logs look like, all my endpoints have the lambda next to them, except dailyMessages, does that mean it cannot find it? How come it is reachable by /dailYMessages:
Route (app) Size First Load JS
┌ ○ / 6.92 kB 91.2 kB
├ ○ /_not-found 882 B 85.2 kB
├ ○ /dailyMessages 0 B 0 B
├ λ / 0 B 0 B
├ λ / 0 B 0 B
├ λ / 0 B 0 B
├ λ / 0 B 0 B
├ λ / 0 B 0 B
├ λ / 0 B 0 B
├ λ / 0 B 0 B
└ λ / 0 B 0 B

Any help or suggestions on places to look would be greatly appreacited :slight_smile:

Hi, @ndrb! Welcome to the Vercel Community :smile:

Thank you for your patience. I recommend that you troubleshoot through our recently published guide in case it’s helpful: Troubleshooting Vercel Cron Jobs

@ndrb, did the troubleshooting guide solve your issue? Or did you find another work around?

Your situation describes mine exactly, except that I’m on the Hobby plan. But the only documented difference is the timing.

@pawlean, I followed the troubleshooting guide and added force-dynamic. That did result in what seemed like an improvement (the job executed and logs showed up), but it was only temporary. Now when I manually run the job, the logs show up, but it’s the exact same logs as before, only with updated timestamps. The code does not appear to execute because I don’t receive the email I expect to receive. This is especially frustrating because it means I cannot trust the logs to help debug the issue.

I would love to know what I need to do to make the cron jobs execute reliably with reliable logs.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.