#Querying api for status

10 messages · Page 1 of 1 (latest)

radiant spruce
#

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?

brittle sleetBOT
#

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](https://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!
radiant spruce
#

Would actionRetrier resolve this?

golden matrix
#

ctx.scheduler.runAfter(0, ...) can run an action in the background and then return to the user while the action is still running

crude lark
#

^ 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

radiant spruce
#

Ah okay, I understand, thank you for the help 😄

crude lark
#

no problem!

radiant spruce
#

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();. 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?

crude lark
#

they can run for up to 10 minutes