#Schedule function

26 messages · Page 1 of 1 (latest)

meager shadow
#

hello there
I need to execute a specific task every minute on creation (api.some_task.create), but only for a duration of 10 minutes. Could someone please guide me on how to schedule this function?

coral estuaryBOT
#

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!

uncut rivet
oak totem
uncut rivet
#

oooo or that!

oak totem
#

Sory lol

uncut rivet
#

The crons approach is cool too

oak totem
#

Yeah indy suggested this the other day

uncut rivet
#

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});
  }
})
meager shadow
#

@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,
);
uncut rivet
#

@meager shadow does the scheduler.runAfter solution above make sense?

meager shadow
#

it works...
but i dont want to call cron job every minute

#

why do i call cron if nobody interact

uncut rivet
#

@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

meager shadow
#

self repetation ?

#

how to?

uncut rivet
meager shadow
#

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