Module: Tengine::Core::OptimisticLock
- Extended by:
- ActiveSupport::Concern
- Includes:
- SafeUpdatable
- Included in:
- Session
- Defined in:
- lib/tengine/core/optimistic_lock.rb
Defined Under Namespace
Modules: ClassMethods
Classes: RetryOverError
Constant Summary
collapse
- DEFAULT_RETRY_COUNT =
(ENV['TENGINE_OPTIMISTIC_LOCK_RETRY_MAX'] || 5).to_i
Class Method Summary
collapse
Instance Method Summary
collapse
safemode, #update_in_safe_mode
Class Method Details
.update_with_lock_stack ⇒ Object
23
24
25
|
# File 'lib/tengine/core/optimistic_lock.rb', line 23
def update_with_lock_stack
@update_with_lock_stack ||= []
end
|
Instance Method Details
#__update_with_lock__ ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/tengine/core/optimistic_lock.rb', line 56
def __update_with_lock__
lock_field_name = self.class.locking_field
current_version = self.send(lock_field_name)
hash = as_document.dup.stringify_keys
hash.delete("_id") new_version = current_version + 1
hash[lock_field_name.to_s] = new_version
selector = { :_id => self.id, lock_field_name.to_sym => current_version }
result = update_in_safe_mode(self.class.collection, selector, hash)
send("#{lock_field_name}=", new_version)
result["updatedExisting"] && !result["err"]
end
|
#update_with_lock(options = {}) ⇒ Object