cps-user3
cps-user314mo ago

Is there a way to modify the arguments of a schedule function?

export const getScheduledMessage = query({ args: { id: v.id("_scheduled_functions"), }, handler: async (ctx, args) => { return await ctx.db.system.get(args.id); }, }); I'd like to fetch the schedule, just like in the example document, and modify the arguments that are reserved. Is there any good way?
3 Replies
Indy
Indy14mo ago
You can't modify the arguments of an already scheduled function. However, you can cancel and schedule a new one: https://docs.convex.dev/scheduling/scheduled-functions#canceling-scheduled-functions https://docs.convex.dev/scheduling/scheduled-functions#scheduling-functions
Scheduled Functions | Convex Developer Hub
Convex allows you to schedule functions to run in the future. This allows you to
ian
ian14mo ago
A cool thing about this approach is that it has the same transactional correctness elsewhere in Convex. Either it will cancel the scheduled function and change the parameters or it will see the function as already started. It won’t have a data race where you run the scheduled function twice (assuming you only schedule a new one if you see the status as pending)
cps-user3
cps-user3OP14mo ago
Thank you so much!

Did you find this page helpful?