DEV Community

Cover image for How to create a Vercel Cron Job using NextJS 13

How to create a Vercel Cron Job using NextJS 13

Chris Nowicki on April 19, 2023

As a new developer I am constantly trying new technologies and recently have really enjoyed coding in NextJS 13 using their /app directory experime...
Collapse
 
goodjoe01 profile image
Ivan Gamboa

I am following everything you put in the post, but for some reason my cronjob does not run at the scheduled time, I enter the vercel dashboard and I see the cronjob created correctly, also when I hit "run" if I see the log, but automatically does not run it.

I am using version "13.4.13", from next.

Collapse
 
rrhapsod profile image
Renan Rondon

Same problem here. I'm on Next 13.4.17

Collapse
 
chrisnowicki profile image
Chris Nowicki

Hi @rrhapsod, Are you using a Vercel Pro account? Can you provide a code snippet of your vercel.json file? or a link to your repository?

Thread Thread
 
rrhapsod profile image
Renan Rondon

It's the exact same problem from this discussion:
github.com/orgs/vercel/discussions...

Thread Thread
 
chrisnowicki profile image
Chris Nowicki

question ... in your build logs is it a server route or does it show a circle next to it indicating a static route?

Thread Thread
 
chrisnowicki profile image
Chris Nowicki

If it shows a circle or static route ... try adding this in the route right before the function:

// Nextjs route segment config
export const dynamic = 'force-dynamic' // Force dynamic (server) route instead of static page
Enter fullscreen mode Exit fullscreen mode
Thread Thread
 
chrisnowicki profile image
Chris Nowicki

This is what I mean by if the route is shown as static or a server component. Here is a screen shot of my latest build log. /api/github-metrics-sync is a Cron Job.

Image description

Collapse
 
goodjoe01 profile image
Ivan Gamboa

Hi Renan, I'm using upstash service and it works perfectly.

I think the "issue" with vercel was that it was indicating a local time but you must indicate UTC time, I think that was the "problem". I noticed that when using upstash, since in this service it specifies that.

Thread Thread
 
chrisnowicki profile image
Chris Nowicki

@goodjoe01 great! looks like you figured it out?

Thread Thread
 
goodjoe01 profile image
Ivan Gamboa

I did, thank you anyway!

Collapse
 
chrisnowicki profile image
Chris Nowicki • Edited

Hi @goodjoe01, Are you using a Vercel Pro account? Can you provide a code snippet of your vercel.json file? or a link to your repository?