Skip to content

Instantly share code, notes, and snippets.

@steveluscher
Created April 15, 2009 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steveluscher/95977 to your computer and use it in GitHub Desktop.
Save steveluscher/95977 to your computer and use it in GitHub Desktop.
# 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