Next.js Discord

Discord Forum

Cron Job running on each deployment

Answered
Broad-snouted Caiman posted this in #help-forum
Open in Discord
Broad-snouted CaimanOP
Hello everyone,

I have a fairly basic application hosted on Vercel which contains a cron job that should run once a month (https://gyazo.com/034a328882bc757d2f6723b59cf01d4c)



It runs fine when I run it manually.
However, every time I push new changes on my main branch (which triggers a new deployment), the cron job runs.

Currently, this cron sends an automated email based on a list of emails. This is quite problematic.

Could you please tell me more?
Thank you very much.
Answered by riský
Like inside the script, check of the date is the first of the month (and maybe even time of day) and return early if it isn't
View full answer

10 Replies

Inside the Cron script, you could check the date
Broad-snouted CaimanOP
Meaning? I'm not sure I understand :mild_panic:
Like inside the script, check of the date is the first of the month (and maybe even time of day) and return early if it isn't
Answer
Kinda still problematic for pushing code on the first tho
Broad-snouted CaimanOP
Ahhhh okay I can see how that could be an interesting approach, I'll keep that option for myself! Thank buddy
but tbh i am a little surprised that it does that... i thought that it would just do the cron time 😭
Broad-snouted CaimanOP
That's why I came to make a request here, I find this kind of behavior a bit strange, I think maybe there's something to configure on vercel directly or in 'vercel.json' ...
Or disabling the cron before deploying might also be a viable option.
well, you would have to create a request on vercels github, as they like never look here
im marking this as solved (as nothing better i think exists), but please come back here if you come across a better method
Broad-snouted CaimanOP
Ok, thank you for ur support, have a great day 🙂