On Sep 21, 3:57 pm, Marnen Laibow-Koser <rails-mailing-l...@andreas-
s.net> wrote:
> 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.
>
>
would have thought that Active Record's optimistic locking would do
the job - if upon saving you get a StaleObjectError you know that you
need to try again.
Fred
>
> > Thanks,
>
> > Florian
>
> Best,
> --
> Marnen Laibow-Koserhttp://www.marnen.org
> [email protected]
> --
> Posted viahttp://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
-~----------~----~----~----~------~----~------~--~---