If you don't mind, yes please 🙏 I want
If you don't mind, yes please 🙏 I want it to run immediately after convex redeploys itself – i.e. nothing external is triggering it
28 Replies
Ok, so you want to run the actual cron job itself only once, correct? I initially read it as that there's an action running, i need to google this real quick
That's right! It's funny to me that Convex has such awesome cron / scheduling features, but I can't seem to just set one to run as a one-off... tricky!!
Thanks for helping 🙂
Yeah, Using cron jobs i don't think it's possible, you're gonna have to run it byweekly or monthly or what ever, cause that's what a cron job is after all
yeah this is what i'm running up against
it's a shame that there's no convex startup routine I can hook into
😅 what?
well, if there was a startup hook that ran after every deploy, I could then use that to (hopefully) trigger an action
it's funny – i can schedule a function to run once at any point in the future, but i can't just get it to run once after every deploy
I recommend posting in #support-community and tagging it as a feature request. I don't recall anyone else request anything like this before. You might want to include more details about your use case (i.e. why this feature would be useful to you) to help them gauge the potential interest for other users.
thanks, when i get some spare time i'll put a request together and explain in more detail about what i'm trying to achieve
This is definitely a first, but just to be clear, the point of a "cron job" is to make repetitive calls, and if you want to run it only once you would use what i described earlier (using a scheduler accessed from a mutation) , you might be able to run the function in the deployment command which also should work, and is the easiest route,
But if you want to make them run once after every deployment programmatically, I think this would require you to do some work beneath just a cron job,
If i remember correctly, you might be able to do this using the platform API, if you cmd+f this
PlatformDeploymentResponse
https://api.convex.dev/v1/openapi.json
But also this is not what you want 😅
If you give us what your use case is in the support thread, we might think of something else
right so its not a cron job then is it
its an event-triggered function
the event is admin deployed new blah
Thanks both. Indeed, I don't want to do this with a cron job (sorry, I thought that was clear) – it was just the only mechanism available right now (that I knew of) which could run something without requiring user interaction or external scripts... As I said, I'd love a 'startup' hook (or something similar), e.g:
@Sara – appreciate you mentioning
PlatformDeploymentResponse – I will definitely take a look at that
I can think of a few use cases for this kind of hook, but I'll consolidate my thoughts and share once I have some more timeThis is a bit problematic, you should consider adding a CLI Command to your deployment command 😅 easiest and fastest way and you don't have to do anything after that
Check this out
https://docs.convex.dev/cli#run-convex-functions
CLI | Convex Developer Hub
Command-line interface for managing Convex projects and functions
Thanks – how would I do this during local dev though, where I'm saving files and convex functions redeploy locally? I'm running the full convex backend stack locally.
Can you give me a description of what you're trying to do?
For dev it would be something like
pnpx convex dev & pnpx convex run functionName
^ you should do some googling and gpting for this one incase it doesn't workIf it was just the initial startup, I would definitely do that
Mhm?
I mean any time a convex function is redeployed though
so if I literally hit CMD + S in a convex file, I'd like to re-run an action
I need to think about this, in the mean time use #support-community
Sure thing – thank you! 🙏
FYI – I figured out a slightly hacky workaround with crons + a node-contained action (which will persist state across the lifetime of the process)
Code example here

with a low interval of 5 seconds, it runs close enough to satisfy my needs
Thia runs every 5 seconds, does it not?
lol – yes, but the state flag prevents the underlying action from ever running again
i'm not over the moon about it, but it works... 🤷♂️
I don't think it does, you should add self destruction to it or something
I don't think the files retain state like you think it does 😅 i might be wrong though
they don't, unless you run it within node with
use node
there are tons of node libs that hold mini state like this
so i think it's a requirement for it to hold runtime state, otherwise lots of node packages would probably break
i'd much prefer a startup hook offered by convex though – so i will put together a feature request at some point 🙂If it works for you then i guess this is resolved
i haven't deployed to a production env yet so it remains to be seen... but i'm hopeful!
thanks for your help / time on this though
much appreciated