Created
April 25, 2019 09:09
-
-
Save krisleech/8e502bde1f64827e73a33d1307b3ae05 to your computer and use it in GitHub Desktop.
ActiveRecord locking
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prevent other processes/threads from updating rows, uses "FOR UPDATE" lock by default: | |
Recruitment::CpmsTotal.transaction do | |
totals = Recruitment::CpmsTotal.not_sent.lock.each # [1] | |
sleep(40) | |
end | |
# [1] each forces query to happen, #all on its own does not. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment