Running ActiveJob after transaction
Transactions! If you know how to cook them they can be a real life saver when it comes to dealing with inconsistent data. But... There's always a "but", am I right? Unfortunately at some point you add code to your system that has sideeffects outside of your database, and obviously transactions won't help you with that. One of such things is Active Job (unless it's based on Delayed Job, which stores your jobs in the same database. Imagine the following scenario: What is wrong here? A lot actually! First of all the SendSmsJob . The SMS is sent regardless of whether a charge via ChargeCustomer succeeds or not. If the charge fails the customer is still going to get the SMS, even though the whole transaction was rolled back. Confusing experience. Second PrepareForShippingJob (it could be any other job referencing the order). What happens if the job is executed before the transaction commits? Payment gateways are not the fastest kids on the block, and