module RedisLocker::ClassMethods

Public Instance Methods

lock_every_method_call(strategy: DEFAULT_STRATEGY, retry_count: DEFAULT_RETRY_COUNT, retry_interval: DEFAULT_RETRY_INTERVAL, exclude: DEFAULT_EXCLUDED_METHODS) click to toggle source
Calls superclass method
# 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) click to toggle source
Calls superclass method
# 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