I have a transaction model in Rails that represents a financial transaction that will be debited from a credit card.
When creating a transaction status :new. When I try to install the board (which will happen in DelayedJob), I update the status to :pending. Any subsequent calls chargewill be ignored if the status is not :new.
Naive version (not relevant to concurrency):
def charge_transaction
return unless status == :new
self.transaction do
self.delay.settle_credit_card
self.update_attribute(:status, :pending)
end
end
def settle_credit_card
end
- load_balanced, , concurrency, (- ). , , ( ) .
( 1)
def charge_transaction
self.with_lock do
self.reload
return unless status == :new
self.delay.settle_credit_card
self.update_attribute(:status, :pending)
end
end
( 2)
def charge_transaction
self.transaction do
self.reload(lock: true)
return unless status == :new
self.delay.settle_credit_card
self.update_attribute(:status, :pending)
end
end
( ) ? ( , ) Rails ? , ?
!