Class: SlowRide::Redis
Constant Summary collapse
- ONE_WEEK =
The default expiration for a given key. We set it to a week and refresh the expiration each time a check is made.
IT’S BEEN …
60 * # seconds 60 * # minutes 24 * # hours 7
Instance Method Summary collapse
- #checked ⇒ Object
- #failed ⇒ Object
- #failure_threshold_exceeded(failed:, checked:) ⇒ Object
-
#initialize(name, failure_threshold:, minimum_checks: 1_000, max_duration: ONE_WEEK, &failure_handler) ⇒ Redis
constructor
days.
Methods inherited from Adapter
Constructor Details
#initialize(name, failure_threshold:, minimum_checks: 1_000, max_duration: ONE_WEEK, &failure_handler) ⇒ Redis
days
62 63 64 65 66 67 68 |
# File 'lib/slow_ride.rb', line 62 def initialize(name, failure_threshold:, minimum_checks: 1_000, max_duration: ONE_WEEK, &failure_handler) super failure_threshold: failure_threshold, minimum_checks: minimum_checks, &failure_handler @name = name @max_duration = max_duration @checked_key = "slow-ride:#{name}:checked" @failed_key = "slow-ride:#{name}:failed" end |
Instance Method Details
#checked ⇒ Object
70 71 72 73 74 75 76 77 78 |
# File 'lib/slow_ride.rb', line 70 def checked SlowRide.redis do |redis| redis.pipelined do |redis| redis.incr @checked_key redis.expire @checked_key, @max_duration redis.expire @failed_key, @max_duration end end.first end |
#failed ⇒ Object
80 81 82 |
# File 'lib/slow_ride.rb', line 80 def failed SlowRide.redis { |redis| redis.incr @failed_key } end |
#failure_threshold_exceeded(failed:, checked:) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/slow_ride.rb', line 84 def failure_threshold_exceeded(failed:, checked:) SlowRide.redis do |redis| redis.pipelined do |redis| redis.del @checked_key redis.del @failed_key end end end |