Class: Sidekiq::Throttler::Storage::Memory
- Inherits:
-
Object
- Object
- Sidekiq::Throttler::Storage::Memory
- Includes:
- Singleton
- Defined in:
- lib/sidekiq/throttler/storage/memory.rb
Overview
Stores job executions in a Hash of Arrays.
Instance Method Summary collapse
-
#append(key, time) ⇒ Object
Add a new entry to the hash.
-
#count(key) ⇒ Fixnum
Number of executions for +key+.
-
#initialize ⇒ Memory
constructor
A new instance of Memory.
-
#prune(key, cutoff) ⇒ Object
Remove entries older than +cutoff+.
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Memory
Returns a new instance of Memory.
9 10 11 |
# File 'lib/sidekiq/throttler/storage/memory.rb', line 9 def initialize @hash = Hash.new { |hash, key| hash[key] = [] } end |
Instance Method Details
#append(key, time) ⇒ Object
Add a new entry to the hash.
45 46 47 |
# File 'lib/sidekiq/throttler/storage/memory.rb', line 45 def append(key, time) @hash[key] << time end |
#count(key) ⇒ Fixnum
Number of executions for +key+.
21 22 23 |
# File 'lib/sidekiq/throttler/storage/memory.rb', line 21 def count(key) @hash[key].length end |
#prune(key, cutoff) ⇒ Object
Remove entries older than +cutoff+.
33 34 35 |
# File 'lib/sidekiq/throttler/storage/memory.rb', line 33 def prune(key, cutoff) @hash[key].reject! { |time| time <= cutoff } end |
#reset ⇒ Object
49 50 51 |
# File 'lib/sidekiq/throttler/storage/memory.rb', line 49 def reset @hash.clear end |