Workpool
If you're using the oncomplete to schedule the next batch, then Workpool might be a better answer. Depending on what you're inserting (can they be inserted in parallel, have to be linear) you may need to do this: https://www.convex.dev/components/workpool#optimize-occ-errors
Convex
Workpool
Workpools give critical tasks priority by organizing async operations into separate, customizable queues.
3 Replies
Hey @Indy , so I currently use this code - as you can see, I use the action-retrier, the caching of an action result, alongside the oncomplete. This seems to do the job just fine, but I am unsure whether this follows the best practices, I think it does - but if you have any input that would be nice, thanks.
I don't think this needs a workpool to be successful?
If this works for you great! The main part that gives me pause is this loop you have in the kickOffFunction
If numChunks is very large, and your "upsert" function
If you are writing over the same rows, then you might be in trouble with repeatedly trying to write on the same records that keep getting invalidated by another mutation. But if they are independent records that you're likely ok.
IIUC you'll only be doing 17 of these batches at the same time, so you'll likely be fine w.r.t. parallelization limits.
But if you expect there to be a lot of writes that contend with each other, and if the number of batches grows quite a bit more, then you'll want to switch the retrier with a workpool to ensure you fit within the Convex parallel function limits: https://docs.convex.dev/production/state/limits#concurrent-function-executions
Limits | Convex Developer Hub
We’d love for you to have unlimited joy building on Convex but engineering