Module: CableX::Cable::RateLimit::BlockCheck

Included in:
Connection
Defined in:
lib/cable_x/cable/rate_limit/block_check.rb

Overview

Process Rate Limit

Instance Method Summary collapse

Instance Method Details

#block_device(unit) ⇒ Object



17
18
19
20
# File 'lib/cable_x/cable/rate_limit/block_check.rb', line 17

def block_device(unit)
  redis_set block_device_key(unit), true, rate_limit[:cool_down].send('second') * 1000
  unit
end

#check_blockObject



9
10
11
# File 'lib/cable_x/cable/rate_limit/block_check.rb', line 9

def check_block
  check_block_unit('second') || check_block_unit('minute') || check_block_unit('hour') if rate_limit
end

#check_block_unit(unit) ⇒ Object



13
14
15
# File 'lib/cable_x/cable/rate_limit/block_check.rb', line 13

def check_block_unit(unit)
  unit if redis_exists block_device_key(unit)
end

#disconnect_client(unit) ⇒ Object



22
23
24
# File 'lib/cable_x/cable/rate_limit/block_check.rb', line 22

def disconnect_client(unit)
  close("Rate limiting: Limit exceeded for per #{unit} Slow down!. Try after some time", false)
end