Ruin9999
Ruin9999•2w ago

Querying api for status

Hey! Anyone know how to run an asynchronous job or something like that can run in the background while I return a value to the user first? I've got this thing where I've got a prompt, generated using an LLM, I am currently calling this API within a convex action and now I need to pass this prompt to a text-to-image model. Problem now is that inference can take quite a while and I don't want users to wait forever on the main page. Does convex have any functionality to allow me to queue actions or something like that so I can query the api for a status while I return something like a predetermined string to my client-side? Or am I going to have to use workers on my server side instead?
8 Replies
Convex Bot
Convex Bot•2w ago
Thanks for posting in <#1088161997662724167>. Reminder: If you have a Convex Pro account, use the Convex Dashboard to file support tickets. - Provide context: What are you trying to achieve, what is the end-user interaction, what are you seeing? (full error message, command output, etc.) - Use search.convex.dev to search Docs, Stack, and Discord all at once. - Additionally, you can post your questions in the Convex Community's <#1228095053885476985> channel to receive a response from AI. - Avoid tagging staff unless specifically instructed. Thank you!
Ruin9999
Ruin9999OP•2w ago
Would actionRetrier resolve this?
lee
lee•2w ago
ctx.scheduler.runAfter(0, ...) can run an action in the background and then return to the user while the action is still running
jamwt
jamwt•2w ago
^ this is the usual answer -- kick off a background action with the above, and then have that background action write out its result using a final mutation convex's reactivity will take care of the rest
Ruin9999
Ruin9999OP•2w ago
Ah okay, I understand, thank you for the help 😄
jamwt
jamwt•2w ago
no problem!
Ruin9999
Ruin9999OP•2w ago
I've now got a bunch of scheduled internalActions that ran and threw a bunch of errors but I still can see them using
ctx.db.system.query("_scheduled_functions").collect();
ctx.db.system.query("_scheduled_functions").collect();
. Actions stay alive for a max of 60 seconds am I right? Do I have to cancel them manually since I am using the scheduler?
jamwt
jamwt•2w ago
they can run for up to 10 minutes but if they throw an exception, they'll exit immediately

Did you find this page helpful?