-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
before_commit example #7
Comments
Thank you very much for the example! However, as I may guess, Sorry, I can't recommend such a usage for In this particular case, it is much better to create |
sounds good! I understand your concerns! Nice to have your feedback 👍 |
Thanks for proposal. Feel free to open new issues if you have any other ideas, concerns, questions, complaints, etc. |
I have an example I think. I'm using this gem in conjunction with https://github.com/leandromoreira/redlock-rb to achieve mutex functionality (e.g. updating a group of records and ensuring this only happens exclusively per organization at one time). The implementation involves acquiring a lock within a transaction and then determining if the lock should be released after the transaction has been committed (to avoid race conditions) or releasing the lock right away. This can be determined by the Is this a good use-case for |
Just creating an issue for giving an example that can be used in the doc for before_commit. Very useful in the case where you want a stripe payment to validate your transaction:
something like that:
payment will only be created if the stripe payment has successfully been done. If payment fail, stripe would raise an error and transaction would rollback.
I think in this case, it's better to make the stripe payment in before_commit cause in the case of a more complex transaction, you don't want to make the stripe payment inside the transaction, at the beginning, and have another piece of code to fail a bit later. Only make the payment if whole transaction went well (before_commit) and only validate the transaction if stripe payment didn't raise an error.
The text was updated successfully, but these errors were encountered: