Class: Neetodeploy::SidekiqMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/neetodeploy/autoscale/sidekiq_middleware.rb

Instance Method Summary collapse

Instance Method Details

#call(worker, job, queue) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/neetodeploy/autoscale/sidekiq_middleware.rb', line 8

def call(worker, job, queue)
  url = URI.parse("http://nd-queue-time-exporter-web-deployment:3000/metrics")

  queues_by_name = ::Sidekiq::Queue.all.each_with_object({}) do |queue_name, obj|
    obj[queue_name.name] = queue_name
  end

  queues = queues_by_name.keys

  queues.each do |queue_obj|
    queue = queues_by_name.fetch(queue_obj) { |name| ::Sidekiq::Queue.new(name) }

    query_params = URI.encode_www_form(app_name: ENV.to_h["NEETODEPLOY_APP_NAME"], process_type: "worker", queue_name: queue_obj, queue_time: queue_time(queue))
    url.query = query_params
    post = Net::HTTP::Post.new(url)
    post["AuthToken"] = "K0An3O3MSyEEMTCnRd1IHgGjdGQkzy"

    begin
      Net::HTTP.start(url.host, url.port, use_ssl: false) do |http|
        http.request(post)
      end
    rescue => e
      puts "Exception in sending post request to exporter from Sidekiq process: #{e.message}"
    end
  end

  yield
end