什么样的异常是由ActiveRecord的::锁募集!? [英] What kind of exception is raised by ActiveRecord::lock!?
问题描述
我使用的锁!在我的code和想赶异常,如果锁抛出!由于某种原因失败(如无法获得该锁)。什么样的异常可以锁定!扔?我查了红宝石文档,但无法找到具体的异常类。
I am using lock! in my code and want to catch the exception thrown if lock! fails for some reason (e.g. cannot get the lock). What kind of exceptions can lock! throw? I checked the ruby docs but couldn't find the specific Exception classes.
感谢。
推荐答案
下面是源的<一个href="https://github.com/rails/rails/blob/master/activerecord/lib/active_record/locking/pessimistic.rb"相对=nofollow>锁定电话。它要求重装及其来源是这样的:
Here is the source for that locking call. It calls reload and its source looks like this:
# File lib/active_record/base.rb, line 2333
2333: def reload(options = nil)
2334: clear_aggregation_cache
2335: clear_association_cache
2336: @attributes.update(self.class.find(self.id, options).instance_variable_get('@attributes'))
2337: @attributes_cache = {}
2338: self
2339: end
所以,当你调用重装。(:锁=>锁)的调用来锁定它是否真的更新该记录的属性
so when you call reload(:lock => lock) as the call to lock does it it really updating the attributes of that record.
有很多不同的情况在这里。你可以尝试锁定该dosnt存在的记录,或锁定一个已经在其他地方锁定。什么错误你有兴趣在追赶?
There are a lot of different situations here. You could try to lock a record that dosnt exist, or lock one that has been locked elsewhere. What error are you interested in catching?
这篇关于什么样的异常是由ActiveRecord的::锁募集!?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!