How to call setInterval from a mutation.
I have been trying to run an internal mutation that decreases a time field in the db every second.
Here is what i have currently. Someone explain to me how i can do that without client mutations?
2 Replies
It sounds like you want to call the mutation from a cron, instead of doing setInterval in an action. https://docs.convex.dev/scheduling/cron-jobs
Cron Jobs | Convex Developer Hub
Convex allows you to schedule functions to run on a recurring basis. For
setInterval works within an action, but it gets canceled when the action returns. so you can end your action with
await new Promise((resolve) => setTimeout(resolve, 5000))
to make your action live for 5 seconds and run as many intervals as it can in that time. for long-term scheduled mutations you would use a cron