#Schedule function
26 messages · Page 1 of 1 (latest)
Thanks for posting in #1088161997662724167.
Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets.
- Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.)
- Use search.convex.dev to search Docs, Stack, and Discord all at once.
- Additionally, you can post your questions in the Convex Community's #1228095053885476985 channel to receive a response from AI.
- Avoid tagging staff unless specifically instructed.
Thank you!
Sounds like you want to use a scheduled function https://docs.convex.dev/scheduling/scheduled-functions that reschedules itself 9 times.
oooo or that!
Sory lol
The crons approach is cool too
Yeah indy suggested this the other day
This version si the component, I wouldn't recommend a component yet for a production app @meager shadow without the caveat that these are still in beta, but you're welcome to try it!
I'd probably write a mutation (or action? what does it need to do?) like
export const aSpecificTask = mutation((ctx, args) => {
console.log('accomplish the task');
if (args.reschedule > 0) {
ctx.scheduler.runAfter(10000, internal.thisFile.aSpecificTask, {reschedule: args.reschedule - 1});
}
})
@uncut rivet @oak totem
at the moment i am executing a cron job for every minute but i know this is not appropriate solution, actually i am practicing web push notification where user gets push notification every minute, after 10 minutes i unsubscribe it auto. in dry code step, i realized why not schedual a function when i am creating subscription instead of executing cron job every minute. here is the working push notifications
crons.ts
crons.interval(
'push notification',
{ minutes: 1 }, // every minute
internal.actions.sendNotification,
);
@meager shadow does the scheduler.runAfter solution above make sense?
it works...
but i dont want to call cron job every minute
why do i call cron if nobody interact
@meager shadow I'm recommending not calling a cron job every minute
instead, scheduling a function
you can either schedule a function that will reschedule itself 9 times
or schedule the function 10 times up front
i c... this one
this makes sense and i will use it
i have one more question
as queries runs immediately
how to call query function inside an event e.g. onClick