#how to check if all actions launched with run after are done
3 messages · Page 1 of 1 (latest)
Hi @red pelican. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
In Convex, every scheduled function is reflected as a document in the _scheduled_functions system table. The runAfter() function returns the id of the scheduled function. You can use this id to check the status of the scheduled function.
Here is an example of how you can retrieve the status of a scheduled function:
const status = await ctx.db.system.get(job);
if (!status) {
throw new Error(`Job ${job} not found`);
}
switch (status.state.kind) {
case "pending":
case "inProgress":
// The function is still running
break;
case "failed":
// The function failed
break;
case "success":
// The function completed successfully
break;
case "canceled":
// The function was canceled
break;
}
In your case, if you launch 100 actions in a for loop, you would need to keep track of all the job ids returned by runAfter(). Then, you can periodically check the status of each job until all of them have either succeeded, failed, or been canceled.
Please note that the results of scheduled functions are available for 7 days after they have completed.