Štosdenfer
Štosdenfer7d ago

Resend in internalAction instead of internalMutation

Currently the docs say to put sending emails via Resend inside an internal mutation. I'm building a webshop which on return from a payment processors runs a mutation to patch the order document's status to paid and then sends an email to the customer that the order is received. If the email fails (happened to me because I put the wrong email while testing), the order document doesn't get patched. I'm guessing this is because the internalMutation also runs transactionally with the patch mutation, and if it fails, it also disgards the patch mutation. If I were to move sending emails from an internal mutation to an internalAction, would that mitigate this? It's crucial that the order get's patched even if the email fails. Thanks!
5 Replies
Convex Bot
Convex Bot7d ago
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 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!
Štosdenfer
ŠtosdenferOP7d ago
I tested it, and it works. Now I'm just wondering if there are any other drawbacks aside from it not running transactionally with the rest of the mutation(s)
ian
ian6d ago
You can also put a try/catch around the resend call to have the resend call roll back but not the rest of the transaction. I think it's often important for an email to transactionally send - e.g. you may want to correct the email so there is a guarantee you send the email correctly. But totally up to you!
Štosdenfer
ŠtosdenferOP6d ago
Okay, didn't know the try/catch method doesn't throw away the entire transaction. I guess it makes sense considering you catch it's throw. Thanks!
ian
ian4d ago
Yeah it's a cool implementation of sub-transactions - the resend component changes will fully roll back, but the parent can continue

Did you find this page helpful?