Sha256: e798d4c4da2dc27a433835ab456b7a503b86b04fc6e7148171d993b983715be8
Contents?: true
Size: 1006 Bytes
Versions: 2
Compression:
Stored size: 1006 Bytes
Contents
module RProxy class CheckSnapshotService def initialize(redis, config) @redis = redis @snapshot_expire_in = 15 * 60 @usage_threshold = config.usage_threshold @cb_url = config.callback_url @logger = config.logger end def call(user, pass, result) return if user.nil? || pass.nil? || result.nil? s_key = "proxy:#{user}-#{pass}:snapshot" snapshot_value = @redis.get(s_key) if snapshot_value.nil? || snapshot_value.empty? @redis.setex(s_key, @snapshot_expire_in, result) else tmp = snapshot_value.to_i - result.to_i if tmp >= @usage_threshold begin connection = RProxy::CallbackService.call(@cb_url, user, pass, tmp) connection.assign_logger(@logger) @redis.setex(s_key, @snapshot_expire_in, result) rescue => e @logger.error("callback service: @id:#{s_key}, #{e.message}") if @logger end end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
r_proxy-0.2.8 | lib/r_proxy/check_snapshot_service.rb |
r_proxy-0.2.7 | lib/r_proxy/check_snapshot_service.rb |