Simple long polling with tRPC

I'm sending an email with a useMutation with MailJet. MailJet's API returns success, even when the email is queued, sending may still fail. They have another API to get the status of the email. I've created a backend function with Quirrel to keep hitting that API until i have a status that's not pending, and then put that status in my DB. Now I want to long-poll my db in the useMutation's onSuccess to check the email status. In order to do that, i create a function in the onSuccess that invalidate's the whole collection's data every second until i get the status. I'd much rather just check the ID of the item with like a Get API repeated and then invalidate everything when it changes... is there a way to do that with tRPC? Also, This sounds overly complex.
3 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
jingleberry
jingleberry2y ago
UseMutation returns a success result and a reference such as a randomly generated taskId Use a separate useQuery to query by taskId to see if it’s completed yet. Only enable this query after the mutation onSuccess is fired
fotoflo
fotofloOP2y ago
🔥 thanks will check carefully
Want results from more Discord servers?
Add your server