Optimistic Locking
Optimistic Locking
For Rails
We had the challenge today for making forms behave well with Optimistic Locking with a rails application. Overall, this is built into the Rails eco-system, with the subtle difference in the way errors are handled. Which is to say poorly.Although this seems to be a problem at the Controller level, this is really related to the model, and the data persistence layer. Hence we chose to use a Concern to provide a method to handle the error gracefully. We included this new concern in any model necessary, and now our apps handle this elegantly.
Quick Code Glance:
module OptimisticLockingNameMeextend ActiveSupport::Concern
def update_with_opt_lock_validation(*args)
update(*args)
rescue ActiveRecord::StaleObjectError
self.lock_version = lock_version_was
errors.add :base, "This #{self.class} has modified while you were editing."
changes.each { |name, values| errors.add name, " that was modified while you were editing was #{values.first}" unless name == "updated_at" }
false
end
end
Dirty, but gets the job done.
For Agile
I love the concept of Optimistic Locking, let's apply this to Agile. Suppose you have a team that is stuck, and everyone knows why it is stuck. Accountability. Who is really accountable when the Team is accountable?
An issue with system performance can arise. Jim believe this is database indexing. John believes this is application performance. John is the DB expert, Jim the application expert. jim cannot force John to take responsibility for the problem, and neither can John make Jim.
They are stuck. And perhaps "optimistically" locked is not the best term.
In the end, someone has to give in. However, this may take input from the management which can only become more involved if Jim & John report to different managers.
In the end, someone has to give in. However, this may take input from the management which can only become more involved if Jim & John report to different managers.
Forget managers. You need leadership to resolve this, and they are not the same thing. There is a great chapter in Agile IT Organization Design. Chapter 6. Accountability.
For today in history
The financial panic of 1857 occurs. It is common after a panic for the electorate to change the governing party. This panic deeply affected the northern states, but left the southern economy relatively untouched.The northern states elected the Republican president Abe Lincoln.
Comments
Post a Comment