neetodeploy-autoscale 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6f0190f5084eb35624b7794eee1edbaf90336fb9933e14ac1e341eb7f01d9702
|
4
|
+
data.tar.gz: b0fed28441c978afd8e92d2b9d1dbb6e76a3d83b8072277f0e98c67cab08e541
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 70f9f059a6262ec11c1b0cfea4f09de2cc923d896a0f268fba3f5d464f95e86128732013d838ea333b21bc5ef573c6e1bc334022ece7b144b173e3d1a9d37f2b
|
7
|
+
data.tar.gz: 44771bb2959cb361bc66112aef8e74ea23e90a8f51bbe12f985b7d91c3796ef13c0a0f01851761c0d8ee5c6f80038164e9addb68e0560543b34a061337eb55d8
|
@@ -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
|
@@ -23,7 +23,7 @@ module Neetodeploy
|
|
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: false) 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.4
|
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-16 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.1.6
|
52
53
|
signing_key:
|
53
54
|
specification_version: 4
|
54
55
|
summary: neetoDeploy autoscaler gem
|