Schedule function
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?
16 Replies
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.
npm
@convex-dev/crons
Convex component for scheduling periodic jobs.. Latest version: 0.1.1, last published: 14 days ago. Start using @convex-dev/crons in your project by running
npm i @convex-dev/crons
. There are no other projects in the npm registry using @convex-dev/crons.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 @M Zeeshan 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
@ballingt @Hmza
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
@M Zeeshan 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
@M Zeeshan 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
self repetation ?
how to?
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
Convex React | Convex Developer Hub
Convex React is the client library enabling your React application to interact