17 Replies
You probably want to schedule a function to run later, see https://docs.convex.dev/scheduling/scheduled-functions
Scheduled Functions | Convex Developer Hub
Convex allows you to schedule functions to run in the future. This allows you to
im just updating a timer across clients. im unsure how this would help
Help me understand what's confusing here, it sounds like you'd like to run some code in the future, in 3 seconds? and then again 3 seconds after that?
its basically a counter. the one we have in games where it shows the time left
it updates every second
if every second wont work, i can do3s
If games are short you can use a long-running action and use timers like you're doing here, just don't return from the function (await a promise) until you're done. But if games can go for more than a few minutes, schedule a function to run in a second.
Then that function you schedule can schedule itself again
is it feasible to schedule one everysecond?
i wanted to try cron. bt cron is very project specific than feature specific. i.e i cant deploy cron based on condition, it would be running all the time and inside i should be having my conditions
Yep, if you use a cron job you'd need to find all the games that need to be updated and update them all in that function
yes it's feasible, if you have issues please let us know
yeah doing that everysecond is very 😬
awesome then ill try that
Could you say more about 😬
i dont think if thats good practice to query and mutate everysecond
and across games
what are your concerns here? Running a cron job once a second and scheduling funtions to run once a second are similar, it depends on how many concurrent games you have for which is more efficient
(if you have 100 games, running a single cron job function once a second sounds better — if you usualy don't have any games, and occasionally have one, then scheduling update functions sounds better)
wow i thought having 100 games and running every second was bad
will try cron then. thanks @Tom
can we start a cron programatically? in the example i can see that we can add arguments for it but they are hardcoded
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
You'd write a cron job that once a second queries for all active games and updates them
how this scales depends on the size of your games
if you want to do this programatically instead you want to use scheduled functions
yeah got that. was just curious if we can pass args to it since i saw this in the example
Yep these are hardcoded, you can pass args but it's always the same args
ok got it
thx