neetodeploy-autoscale 1.0.1 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2b87d45b32ce9e1f5669917a208830d9203789b750cd7b5d7aee76f10a418e1
|
4
|
+
data.tar.gz: d1a2d09de1d74aa01156d71639eaec2696342d0bc85aaca18b942fec7c46b802
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 600c04e4ebe4a6b0f28180d37fb1fb26b54a740bf8e7b9dfaae63bf371ed3711d2be872cb7a144142bff88b1c1339084b71ac63ac7066be5b8a7dc91634ff3f8
|
7
|
+
data.tar.gz: ebf6eb8ddb936f5c643ffdec40e28d6c553c29d8fd9936c1c85ba66ac9b3cb84a42a0d092610b465d20adc9ae179e9c0a160d592e68c1798deb71a85a6037ba6
|
@@ -2,31 +2,24 @@
|
|
2
2
|
|
3
3
|
require "net/http"
|
4
4
|
require "time"
|
5
|
+
require "neetodeploy/autoscale/worker"
|
5
6
|
|
6
7
|
module Neetodeploy
|
7
8
|
class Middleware
|
9
|
+
attr_reader :worker
|
10
|
+
|
8
11
|
def initialize(app)
|
9
12
|
@app = app
|
13
|
+
init_worker
|
10
14
|
end
|
11
15
|
|
12
16
|
def call(env)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
post = Net::HTTP::Post.new(url)
|
20
|
-
post["AuthToken"] = "K0An3O3MSyEEMTCnRd1IHgGjdGQkzy"
|
21
|
-
|
22
|
-
begin
|
23
|
-
Net::HTTP.start(url.host, url.port, use_ssl: true) do |http|
|
24
|
-
http.request(post)
|
25
|
-
end
|
26
|
-
rescue => e
|
27
|
-
puts "Exception in sending post request to exporter from Rails process: #{e.message}"
|
28
|
-
end
|
29
|
-
|
17
|
+
payload = URI.encode_www_form(
|
18
|
+
app_name: ENV.to_h["NEETODEPLOY_APP_NAME"],
|
19
|
+
process_type: "web",
|
20
|
+
queue_time: queue_time(env)
|
21
|
+
)
|
22
|
+
worker.push(payload)
|
30
23
|
@app.call(env)
|
31
24
|
end
|
32
25
|
|
@@ -50,5 +43,11 @@ module Neetodeploy
|
|
50
43
|
|
51
44
|
queue_time.positive? ? queue_time : 0
|
52
45
|
end
|
46
|
+
|
47
|
+
def init_worker
|
48
|
+
return if @worker
|
49
|
+
|
50
|
+
@worker = Neetodeploy::Worker.new
|
51
|
+
end
|
53
52
|
end
|
54
53
|
end
|
@@ -6,7 +6,7 @@ require "time"
|
|
6
6
|
module Neetodeploy
|
7
7
|
class SidekiqMiddleware
|
8
8
|
def call(worker, job, queue)
|
9
|
-
url = URI.parse("
|
9
|
+
url = URI.parse("http://nd-queue-time-exporter-web-deployment:3000/metrics")
|
10
10
|
|
11
11
|
queues_by_name = ::Sidekiq::Queue.all.each_with_object({}) do |queue_name, obj|
|
12
12
|
obj[queue_name.name] = queue_name
|
@@ -17,13 +17,13 @@ module Neetodeploy
|
|
17
17
|
queues.each do |queue_obj|
|
18
18
|
queue = queues_by_name.fetch(queue_obj) { |name| ::Sidekiq::Queue.new(name) }
|
19
19
|
|
20
|
-
query_params = URI.encode_www_form(app_name: ENV.to_h["NEETODEPLOY_APP_NAME"], process_type: "worker",
|
20
|
+
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))
|
21
21
|
url.query = query_params
|
22
22
|
post = Net::HTTP::Post.new(url)
|
23
23
|
post["AuthToken"] = "K0An3O3MSyEEMTCnRd1IHgGjdGQkzy"
|
24
24
|
|
25
25
|
begin
|
26
|
-
Net::HTTP.start(url.host, url.port, use_ssl:
|
26
|
+
Net::HTTP.start(url.host, url.port, use_ssl: false) do |http|
|
27
27
|
http.request(post)
|
28
28
|
end
|
29
29
|
rescue => e
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "time"
|
5
|
+
|
6
|
+
module Neetodeploy
|
7
|
+
class Worker
|
8
|
+
attr_reader :mutex, :queue, :thread
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@mutex = Mutex.new
|
12
|
+
@queue = Queue.new
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
def push(msg)
|
17
|
+
start && queue.push(msg)
|
18
|
+
end
|
19
|
+
|
20
|
+
def start
|
21
|
+
mutex.synchronize do
|
22
|
+
return true if thread&.alive?
|
23
|
+
|
24
|
+
@thread = Thread.new { run }
|
25
|
+
end
|
26
|
+
true
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def run
|
32
|
+
puts "neetodeploy-autoscale: reporter worker started"
|
33
|
+
until queue.empty?
|
34
|
+
queue_time = queue.pop
|
35
|
+
work(queue_time)
|
36
|
+
end
|
37
|
+
puts "neetodeploy-autoscale: reporter stopping worker"
|
38
|
+
end
|
39
|
+
|
40
|
+
def work(payload)
|
41
|
+
url = URI.parse("http://nd-queue-time-exporter-web-deployment:3000/metrics")
|
42
|
+
url.query = payload
|
43
|
+
post = Net::HTTP::Post.new(url)
|
44
|
+
post["AuthToken"] = "K0An3O3MSyEEMTCnRd1IHgGjdGQkzy"
|
45
|
+
|
46
|
+
begin
|
47
|
+
Net::HTTP.start(url.host, url.port, use_ssl: true) do |http|
|
48
|
+
response = http.request(post)
|
49
|
+
end
|
50
|
+
rescue StandardError => e
|
51
|
+
puts "Exception in sending post request to exporter from Rails process: #{e.message}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: neetodeploy-autoscale
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sreeram Venkitesh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: For automatically scaling your Rails application based on network metrics
|
14
14
|
email:
|
@@ -27,6 +27,7 @@ files:
|
|
27
27
|
- lib/neetodeploy/autoscale/railtie.rb
|
28
28
|
- lib/neetodeploy/autoscale/sidekiq_middleware.rb
|
29
29
|
- lib/neetodeploy/autoscale/version.rb
|
30
|
+
- lib/neetodeploy/autoscale/worker.rb
|
30
31
|
homepage: https://neetodeploy.com
|
31
32
|
licenses: []
|
32
33
|
metadata:
|
@@ -48,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
49
|
- !ruby/object:Gem::Version
|
49
50
|
version: '0'
|
50
51
|
requirements: []
|
51
|
-
rubygems_version: 3.
|
52
|
+
rubygems_version: 3.4.10
|
52
53
|
signing_key:
|
53
54
|
specification_version: 4
|
54
55
|
summary: neetoDeploy autoscaler gem
|