Sha256: 282ae1d73fceff111a494c46cbdbb3960a42a23cde7221f5358111351a17213d
Contents?: true
Size: 1.16 KB
Versions: 1
Compression:
Stored size: 1.16 KB
Contents
# frozen_string_literal: true require "net/http" require "time" module Neetodeploy class Worker attr_reader :mutex, :queue, :thread def initialize @mutex = Mutex.new @queue = Queue.new end def push(msg) start && queue.push(msg) end def start mutex.synchronize do return true if thread&.alive? @thread = Thread.new { run } end true end private def run puts "neetodeploy-autoscale: reporter worker started" until queue.empty? queue_time = queue.pop work(queue_time) end puts "neetodeploy-autoscale: reporter stopping worker" end def work(payload) url = URI.parse("http://nd-queue-time-exporter-web-deployment:3000/metrics") url.query = payload post = Net::HTTP::Post.new(url) post["AuthToken"] = "K0An3O3MSyEEMTCnRd1IHgGjdGQkzy" begin Net::HTTP.start(url.host, url.port, use_ssl: false) do |http| response = http.request(post) end rescue StandardError => e puts "Exception in sending post request to exporter from Rails process: #{e.message}" end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
neetodeploy-autoscale-1.0.4 | lib/neetodeploy/autoscale/worker.rb |