#Are the Scheduled Functions a table that can be queried?
4 messages · Page 1 of 1 (latest)
Hi @left rain. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Yes, Scheduled Functions in Convex are reflected as documents in a system table that can be queried. The table is called "_scheduled_functions" and you can query it using specific system methods. Here's how you can do it:
-
The "_scheduled_functions" system table:
Convex stores information about scheduled functions in this table System Tables (https://docs.convex.dev/database/advanced/system-tables). -
Querying the table:
You can usedb.system.queryanddb.system.getmethods to read data from this table. These methods work similarly to the standarddb.queryanddb.getmethods Retrieving scheduled function status (https://docs.convex.dev/scheduling/scheduled-functions#retrieving-scheduled-function-status). -
Example of querying all scheduled functions:
export const listScheduledMessages = query({
args: {},
handler: async (ctx, args) => {
return await ctx.db.system.query("_scheduled_functions").collect();
},
});
- Example of getting a specific scheduled function:
export const getScheduledMessage = query({
args: {
id: v.id("_scheduled_functions"),
},
handler: async (ctx, args) => {
return await ctx.db.system.get(args.id);
},
});
The returned documents contain information about the scheduled function, including its state (pending, in progress, success, failed, or canceled) SystemDataModel (https://docs.convex.dev/api/interfaces/server.SystemDataModel).
You can use these queries to see pending scheduled functions and other states. The state field in the returned document will indicate the current status of the scheduled function.