On Jul 5, 12:04 pm, Onur Gungor <[email protected]>
wrote:
> OK. Then it means Mutex'es don't work in a multi-process Passenger
> setup.
>
> But then how can I synchronize this method's usage? I am very new to web
> development so I just heard about database locking.
>
> Simply, how should I use the
> ActiveRecord::Transactions::ClassMethods#transaction and
> ActiveRecord::Base#lock!?
>
> Would it be OK to create a model and its corresponding table for just
> locking? i.e. Lock model and locks table.

That or rails' optimistic locking might be useful. I would usually shy
away from creating a Lock model, it just seems a bit artificial. I
would probably stick a locked_by_foo column on the appropriate model
and use that to tell whether a particular object is being updated (and
use optimistic locking in conjunction with that)

Fred
>
> Then use them like this:
>
> Lock.transaction do
>
>   lock = Lock.find(1)
>   lock.lock!
>
>   # do my stuff which should be done by only one process at a time.
>
> end
>
> Thanks,
> Onur
> --
> 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to