Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/b29b9ac9b43a5281
seconds_to_wait_for_lock = 5
begin
raise "Timed out while trying to acquire lock" unless connection.select_value("SELECT GET_LOCK('order_lock_for_product_#{@product.id}', #{seconds_to_wait_for_lock})") == "1"
# ... validate order availability ...
# ... create orders ...
rescue
# ... oh oh ...
# ... a stuck lock? ...
# ... somebody do something! ...
ensure
connection.select_value("SELECT RELEASE_LOCK('order_lock_for_product_#{@product.id}')")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment