Forum: Ruby on Rails ActiveRecord transactions & thread safety

870d77abc648ef1299376071e8471455?d=identicon&s=25 Alexey Chernenkov (Guest)
on 2014-06-03 06:34
(Received via mailing list)
My question is about AR transactions feature. Is it thread safe?
Is it safe to use both `*ActiveRecord::Base.transaction do ...*` and
`*Account.transaction
do ...*` statements?

I plan to use Puma as web server, and Sidekiq for background processing.
Is there some tricks I should know about?

Thanks!
81b61875e41eaa58887543635d556fca?d=identicon&s=25 Frederick Cheung (Guest)
on 2014-06-03 09:13
(Received via mailing list)
On Tuesday, June 3, 2014 5:32:57 AM UTC+1, Alexey Chernenkov wrote:
> My question is about AR transactions feature. Is it thread safe?
> Is it safe to use both `ActiveRecord::Base.transaction do ...` and
`Account.transaction do ...` statements?
>
>

It should be - a connection is only ever used by 1 thread at a time (and
unless you have configured Account to use a separate connection then AR
won't be default create nested transactions/save points )If you could
show in more detail what you are doing then a more considered reply
might be possible.

Fred
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.