Module: RedisLocker::ClassMethods
- Defined in:
- lib/redis_locker.rb
Instance Method Summary collapse
- #lock_every_method_call(strategy: DEFAULT_STRATEGY, retry_count: DEFAULT_RETRY_COUNT, retry_interval: DEFAULT_RETRY_INTERVAL, exclude: DEFAULT_EXCLUDED_METHODS) ⇒ Object
- #lock_method(method, strategy: DEFAULT_STRATEGY, retry_count: DEFAULT_RETRY_COUNT, retry_interval: DEFAULT_RETRY_INTERVAL) ⇒ Object
Instance Method Details
#lock_every_method_call(strategy: DEFAULT_STRATEGY, retry_count: DEFAULT_RETRY_COUNT, retry_interval: DEFAULT_RETRY_INTERVAL, exclude: DEFAULT_EXCLUDED_METHODS) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/redis_locker.rb', line 36 def lock_every_method_call(strategy: DEFAULT_STRATEGY, retry_count: DEFAULT_RETRY_COUNT, retry_interval: DEFAULT_RETRY_INTERVAL, exclude: DEFAULT_EXCLUDED_METHODS) interceptor = self.const_get("#{name.split('::').last}Interceptor") self.define_singleton_method(:method_added) do |method| return super(method) if exclude.include? method interceptor.define_method(method) do |*args, **opts, &block| returned_value = nil method_locker(method).with_redis_lock strategy: strategy, retry_count: retry_count, retry_interval: retry_interval do returned_value = super(*args, **opts, &block) end returned_value end end end |
#lock_method(method, strategy: DEFAULT_STRATEGY, retry_count: DEFAULT_RETRY_COUNT, retry_interval: DEFAULT_RETRY_INTERVAL) ⇒ Object
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/redis_locker.rb', line 52 def lock_method(method, strategy: DEFAULT_STRATEGY, retry_count: DEFAULT_RETRY_COUNT, retry_interval: DEFAULT_RETRY_INTERVAL) interceptor = self.const_get("#{name.split('::').last}Interceptor") interceptor.define_method(method) do |*args, **opts, &block| returned_value = nil method_locker(method).with_redis_lock strategy: strategy, retry_count: retry_count, retry_interval: retry_interval do returned_value = super(*args, **opts, &block) end returned_value end end |