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:
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