How can I cancel scheduled?
export const cancelMessage = mutation({
args: {
id: v.id("_scheduled_functions"),
},
handler: async (ctx, args) => {
await ctx.scheduler.cancel(args.id);
},
});
Property 'cancel' does not exist on type 'Scheduler'.
I followed the example in the documentation, but an error occurred. What's the cause?
5 Replies
What version of convex are you using? Cancelation got introduced in convex 1.6
Convex News
Announcing Convex 1.6
Version 1.6 of the convex npm package:
* Adds a new interface for querying system tables which can be used to programmatically query scheduling state or list storage objects.
* Adds canceling scheduled function.
* Adds "skip" to usePaginatedQuery().
* Adds a new npx convex logout CLI command.
* Updates the syntax used in
Thank you. I didn't think of a version.
I'd like to ask you one more question.
I implemented the payment every month, and I want to store the ID of the schedule in the database.
Is there any good way?
export const paymentSchedule = action({
args: {
id: v.id("apiLimit"),
billingKey: v.string(),
customerKey: v.string(),
customerName: v.optional(v.any())
},
handler: async (ctx, { id, billingKey, customerKey, customerName }) => {
const paymentResponse = await sendTossPayment(billingKey, customerKey, customerName);
if (paymentResponse.status === 'DONE') {
const paymentTime = Date.parse(paymentResponse.approvedAt);
await ctx.scheduler.runAfter(
30 * 24 * 60 * 60 * 1000,
api.payments.paymentSchedule,
{ id, billingKey, customerKey, customerName }
);
};
}
});
Hey @cps-user3
runAfter
returns an Id<"_scheduled_functions"
which you can save in your DB using a mutation.
Check out the docs https://docs.convex.dev/scheduling/scheduled-functionsScheduled Functions | Convex Developer Hub
Convex allows you to schedule functions to run in the future. This allows you to
Thank you so much.