How can we handle DB Transactions? #4
-
I have a question regarding DB Transactions. ExampleMoney Transfer from account A to Account B. What I would want to achieve is to make the two jobs above as a unit. All jobs or none. Would you please suggest a way to do that? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
If i understand correctly you're looking into a reversal in case one of these jobs fail? If so, this is an interesting case! This makes a good case for an operation. Important However, if you were to do it manually at the architecture level, here's one suggestion to make it happen:
Based on the result from the If failed run
The reason why the second job isn't named with the same convention (revert etc.) is because it contains more work than General Suggestions
Please let me know your thoughts on the above @yasalkhatib |
Beta Was this translation helpful? Give feedback.
If i understand correctly you're looking into a reversal in case one of these jobs fail? If so, this is an interesting case!
This makes a good case for an operation.
Important
Before going into the details, I'd like to highlight that these are usually handled at the DB layer and not at the architecture layer, where you would create a DB transaction which will revert itself when things don't go as planned.
However, if you were to do it manually at the architecture level, here's one suggestion to make it happen:
TransferMoneyOperation($fromAccount, $toAccount)
-> returnsTransferStatus
object summarising the jobs' resultsWithdrawMoneyFromAccountJob($fromAccount, $amount)
DepositMoneyInA…