Cron jobs running from Preview Deployments
I've added a new cron job in my convex, but now it seems like every time I make changes to the convex, the cron jobs from preview deployments are still running, because the cron job function notifies messages in Slack, and I'm getting 5 messages with only one with up-to-date message (meaning other 4 messages are from preview deployments)
5 Replies
Yep crons run on preview deployments (with whatever code was pushed to that preview deployment). If there are crons you don't want to run from preview deployments, I'd suggest using an environment variable that has a different value in your prod deployment vs. preview deployments and gating on that within the cron to either no-op or do something different (e.g. post slack messages to a different channel to filter out the ones from preview deployments). Would that work for your use case?
Does convex have an environmental variable by default, that tells which environment you are in? (prod, dev, preview)
I'm thinking of the simplest way to implement that change. I don't want to change env variable each time the new preview deployment environment pops up.
Does convex have an environmental variable by default, that tells which environment you are in? (prod, dev, preview)We have considered adding this, but alas we don't have this atm. It should be easy to set up: process.env.RUN_CRONS Only set RUN_CRONS on your production and dev deployments.
In case you didn't see it, you can set project-level default env variables, so they're set automatically when a preview deploy is created: https://docs.convex.dev/production/environment-variables#project-environment-variable-defaults
You could set RUN_CRONS to "off" there as Michal suggests. Note that setting it to
false
will result in "false"
since env variables are stringsEnvironment Variables | Convex Developer Hub
Store and access environment variables in Convex
That will work. Thanks!