search for: staleobjecterror

Displaying 15 results from an estimated 15 matches for "staleobjecterror".

2009 Aug 10
1
[PATCH server] Fixed db-omatic so it doesn't die due to an unhandled ActiveRecord::StaleObjectError exception.
...=> ["vm_id = ? AND time_ended is NULL", vm.id]) if state == Vm::STATE_RUNNING @@ -215,7 +217,14 @@ class DbOmatic < Qpid::Qmf::Console end vm.state = state - vm.save! + + begin + vm.save! + rescue ActiveRecord::StaleObjectError => e + @logger.error "Optimistic locking failed for VM #{vm.description}, retrying." + @logger.error e.backtrace + return update_domain_state(domain, state_override) + end domain[:synced] = true end @@ -234,7 +243,14 @@ class DbOm...
2006 May 09
7
When to use optimistic locking?
Hi All, I''m having some trouble deciding when and how to implement optimistic locking. Let''s say I have a multiuser Rails app, and let''s say it stores, among other things "vital" customer information. The standard methods created by the Rails generate scaffold script look like this: def edit @customer = Customer.find(params[:id]) end
2008 Feb 08
2
update_Attributes stale Object error
Hi, IN one of my unit tests I get an ActiveRecord::StaleObjectError: Attempted to update a stale object object.save! in object I have apart from other stuff an after_save method, which calls object.assosication.update_attributes(...) If I remove that line from my code my tests succeeds. Unfortunetly, I do not understand why an update_attributes call can generat...
2006 Feb 23
7
Session Based Record Locking - Solutions?
All, I''ve written a simple job/opportunity tracking database app via RoR. I have about 10 internal users. Sometimes 2 people will want to update the same record at more or less the same time and they collide. In particular user 1 may edit a record, then get distracted, and finally an hour later they click save. During that hour user 2 may have pulled up the record, edited it, and
2009 May 19
4
proper way to ensure atomic model changes
Hi! Say we have a rails active-record-based model called "instance" which can have different states - STOPPED, RUNNING, STARTING_UP, SHUTTING_DOWN, etc... There is a method #start which changes the instance state to STARTING_UP only if it is STOPPED. def start if self.state == STOPPED self.state = STARTING_UP self.save ... end end As you understand if we have multiple
2006 Aug 16
1
Stale object errors
...g something like: def update_volatile_object num_attempts = 5 while num_attempts>0 begin yield # the block should do something along the lines of Message.update(blah) break # If we got here, we didn''t raise a stale object error rescue ActiveRecord::StaleObjectError => e num_attempts -= 1 end end raise DatabaseSeemsTooDamnBusy if num_attempts==0 end ...but it feels like I''m missing something - does Rails supply any functionality to do this for me? Any suggestions on how to improve the above?
2006 Apr 11
1
Implementing Optimistic Offline Lock - How ?
I understand that ActiveRecord supports the "optimistic offline lock"-pattern through magic fields (created_at, updated_at). However, a scaffolded CRUD-Controller doesn''t generate the necessary code to support this feature (the model state gets lost between two action calls). What is the best practice to prevent users from overwriting objects with outdated data ? --
2006 Jan 29
9
Specify options with habtm
Hi all I have the following models: class member has_and_belongs_to_many :disc_jockeys end class disc_jockey has_and_belongs_to_many :members end The relation table is called disc_jockeys_members and has the following fields: disc_jockeys_members(disc_jockey_id, member_id, status) So far, the field status can have values like valid, invalid, locked etc., but it is not regarded yet by
2007 Mar 25
1
Optimistic locking and update_attributes: not working?
...getting optimistic locking (OL) to work in my app, even though all of the pieces are there: * table has lock_version column, with default of 0 (zero) * lock_version column is being incremented by the first update (but the second doesn''t catch it) * I''m trapping for ActiveRecord::StaleObjectError, but it is never thrown But nothing seems to work. Note that currently, I''m still in development mode and using the scaffolding code that relies on update_attributes, but I haven''t found any documentation that states whether OL works/does not work in development mode or with upd...
2009 Jan 31
0
save after delete returns true but actually fails
...ltaneously. The same thing occurs when the model is using optimistic locking. It seems to me that in this case, it would be nice if the second doc.save raised an exception. (If one makes a change to one of doc''s fields immediately before the second save, then one does get an ActiveRecord::StaleObjectError exception.) - Farmer -- 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 rubyonrails-talk-/JYPxA39Uh5T...
2007 Mar 03
11
Beyond multiple return values
...than fiddling with lambdas everytime this sort of behaviour is needed But can we go further ? I was writing a test today and I wanted the first call to a method to raise an exception and the next call to return a value (I was testing a method on an ActiveRecord object where if save! raises StaleObjectError then we reload and retry in the proper way, the second call to save! shouldn''t raise.). The same basic method works: lambdas = [lambda {raise ''Foo''}, lambda {return true}] object.stubs(:save!).returns {lambda {lambdas.shift.call}} It''s a lot less readable th...
2009 Feb 10
2
rescue_from for NoMethodError
Hi everyone, I was just trying to catch some exceptions in my app, for "Record Not Found" I used this in my application.rb file rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found rescue_from ActionController::NoMethodError, :with => :show_error private def record_not_found render :text => "404 Not Found", :status =>
2006 May 09
5
Shared Queue / Exclusive Query Results
My application is going to have a work queue of scheduled tasks stored in the DB. This work queue will be shared across multiple Rails app servers. I need a way to ensure that no two servers get the same jobs if multiple servers pop jobs off the top of the queue simultaneously. Is there a fairly simple way to acheive this? Or do I need to come up with some fancy secondary server to dispatch
2007 Apr 12
15
Preview of Latest Mocha Changes
I''ve finally managed to find some time to do some serious work on Mocha. There are some code snippets on my blog (http://blog.floehopper.org/articles/2007/04/12/preview-of-latest-mocha-changes) showing the new functionality available in trunk (revision 128). I don''t don''t know how many people out there are using trunk, but it would be great to get some feedback on these
2005 Dec 20
12
How to model "Expense Report" in Rails MVC
1st: I am a newbie to Rails & to pure OO. Q: I want to use rails for creating a "master-detail" form. page layout will allow users to type in an "expense report header" and as many "expense report lines" as they need to. I understand how to wrap the final submit action using "transaction" to ensure the inserts to the database happen within the same