Debounce action from mutation
Is it possible to debounce an action from a mutation?
I have a use case where I'm using Convex to sync information from a text editor on the frontend (Tiptap). I'm using mutations to update the database with the current state of the text editor (using single flight) and I'm calling
scheduler.runAfter(0, "actions/some-api-call")
at the end of those mutations.
This works, but since there is a ($) cost to each run of the some-api-call
action, I'd like to debounce it, but haven't found a way to do this without putting the debounce on the client-side. Any thoughts?4 Replies
afk, but I wrote a post on stack.convex.dev on job tables. You could schedule the action 500ms in the future and write to a table. When the action fires it can runQuery to decide whether to run or not. Depending on how long it’s been since the last run & whether there’s another scheduled already, eg
ahh that pattern should work, thanks!
Would probably be a mutation, not a query, so it could update the table to say one started in the same transaction as the read
Here's the article 🙂 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.