What's the best way to manage long running functions in convex actions?
I have 3 async functions that depend one on each other so I can not do Promise.all
I'm running these in internal action ("use node")
each function can take ~5 seconds so total action execution time could take ~15 seconds
Is this is healthy for convex? is there a better way todo this?
9 Replies
Am I understanding this right that they need to run sequentially, and you don't want to just run the code from one place inline? Having a top level action is the simple approach, but it contributes to action execution time for something that is running idle. You could also have each one schedule the next one when it's done.
An older post that still has some good ideas: https://stack.convex.dev/background-job-management
Background Job Management
Implement asynchronous job patterns using a table to track progress. Fire-and-forget, cancelation, timeouts, and more.
I might have misunderstood - if it's not calling 3 convex functions but just doing inline slow operations, then you're doing it right. Actions can run for up to 10m so it's "healthy" for Convex.
Yeah I want to run 3 long running api calls (no reading writing convex data).
Great. Then yes just calling them from an action that sits and waits is what I would do.
how does that impact my billing though? Execution time in lamdas cost money, right? I wouldn't expect that function which runs 15-20s be running very often though but anyway
For actions you pay for GBh - a combo of how much memory it's using and how long it runs. If you're using 5MB and running for 15s, you can do ~1 million of them each month on the free plan (20GBh) or 12 million on the pro plan, after which every 1 million calls would be ~$6 if my napkin math is right
I'm not sure how much memory you'd be using though. You can check in the log stream and attribute it to each function call if you want though
Log Streams | Convex Developer Hub
Configure logging integrations for your Convex deployment
other solutions would look like calling something that calls back to a webhook, or kicking something off and polling with the scheduler, but personally I wouldn't worry about 15s - the cost of whatever service you're hitting is likely much larger than some action compute in Convex
thanks for reply!