#Are the Scheduled Functions a table that can be queried?

4 messages · Page 1 of 1 (latest)

left rain
#

Is there a table that we can query to see pending scheduled functions and whatnot? If so, how?

zealous bridgeBOT
#

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:

  1. The "_scheduled_functions" system table:
    Convex stores information about scheduled functions in this table System Tables (https://docs.convex.dev/database/advanced/system-tables).

  2. Querying the table:
    You can use db.system.query and db.system.get methods to read data from this table. These methods work similarly to the standard db.query and db.get methods Retrieving scheduled function status (https://docs.convex.dev/scheduling/scheduled-functions#retrieving-scheduled-function-status).

  3. Example of querying all scheduled functions:

export const listScheduledMessages = query({  
  args: {},  
  handler: async (ctx, args) => {  
    return await ctx.db.system.query("_scheduled_functions").collect();  
  },  
});  
  1. 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.