Class: Sidekiq::Throttler::Storage::Memory

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/sidekiq/throttler/storage/memory.rb

Overview

Stores job executions in a Hash of Arrays.

Instance Method Summary collapse

Constructor Details

#initializeMemory


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

#resetObject


49
50
51
# File 'lib/sidekiq/throttler/storage/memory.rb', line 49

def reset
  @hash.clear
end