Class: OurEelHacks::Sidekiq

Inherits:
Middleware show all
Includes:
Defer::Celluloid
Defined in:
lib/our-eel-hacks/sidekiq.rb

Instance Method Summary collapse

Methods included from Defer::Celluloid

#trigger_scaling

Constructor Details

#initialize(flavor = :sidekiq) ⇒ Sidekiq

Returns a new instance of Sidekiq.



7
8
9
# File 'lib/our-eel-hacks/sidekiq.rb', line 7

def initialize(flavor=:sidekiq)
  super
end

Instance Method Details

#call(worker_class, item, queue) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/our-eel-hacks/sidekiq.rb', line 11

def call(worker_class, item, queue)
  begin
    autoscale(get_queue_length(queue))
  rescue => ex
    puts "Problem in autoscaling: #{ex.inspect}"
  end
  yield
end

#get_queue_length(queue) ⇒ Object



20
21
22
23
24
# File 'lib/our-eel-hacks/sidekiq.rb', line 20

def get_queue_length(queue)
  {"queue_length" => ::Sidekiq.redis do |conn|
    conn.llen("queue:#{queue}") || 0
  end }
end