Florian Dejako wrote: > My app sends out activation keys from a list of unassigned keys to > customers. An appropriate model action in the activation key model > would look something like this: > > named_scope :available, :conditions => 'available IS NULL' > > def fetch_available_key > key = ActivationKey.available.first > key.assigned = DateTime.now > key.save > return key > end > > What's the best way to deal with concurrent requests in this > situation? My deployment server uses passenger, the database is MySQL > 5.x.
I've never quite done this, but from the docs it seems that you probably want pessimistic locking. Make sure that you're using a mySQL storage engine that supports the appropriate features; better yet, try switching to PostgreSQL. > > Thanks, > > Florian Best, -- Marnen Laibow-Koser http://www.marnen.org [email protected] -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---

