hirefire-resource 0.4.2 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +4 -4
- data/hirefire-resource.gemspec +1 -1
- data/lib/hirefire/middleware.rb +33 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 33c33c7654d2bec9a8f5a0325c508fcf1314555f1409f693808189057558a71f
|
4
|
+
data.tar.gz: dc51a264bac728b99397178bbf741d7b61589d57d9cdf6fb40ade130bdf51b22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10103ce68c4fb42249f533cc89b824a8ec200c4fb04ebfb059f3949cae0b7dda53eb2005d8c763dab431619be794fd9307847d4b57909c16d8bf0ba775378cb3
|
7
|
+
data.tar.gz: edaee01b36999e985f8f2858f81c99f89d119705b0e4a840190bb2d70cd282b4d86874501373992aabee7ca02534949fb6fa193cde119c5151d1d8b047a5b720
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
## [HireFire](
|
1
|
+
## [HireFire](https://www.hirefire.io/) - Autoscaling for your Heroku dynos
|
2
2
|
|
3
|
-
Load-based scaling, schedule-based scaling, dyno crash recovery, for [Heroku](
|
3
|
+
Load-based scaling, schedule-based scaling, dyno crash recovery, for [Heroku](https://www.heroku.com/) web- and worker dynos.
|
4
4
|
|
5
5
|
---
|
6
6
|
|
@@ -27,7 +27,7 @@ It supports practically any Rack-based application or framework, such as:
|
|
27
27
|
We provide convenient macros for the above mentioned worker libraries to calculate the queue size for each of them.
|
28
28
|
If you wish to conribute more macros for other existing worker libraries feel free to send us a pull request.
|
29
29
|
|
30
|
-
Here is an example with
|
30
|
+
Here is an example with Rails 3+
|
31
31
|
|
32
32
|
First, add the gem to your `Gemfile`:
|
33
33
|
|
@@ -83,7 +83,7 @@ dj_worker: QUEUES=encode,compress bundle exec rake jobs:work
|
|
83
83
|
|
84
84
|
Now that HireFire will scale both of the these dyno types based on their individual queue sizes. To customize how they scale, log in to the HireFire web interface.
|
85
85
|
|
86
|
-
Visit the [official website](
|
86
|
+
Visit the [official website](https://www.hirefire.io/) for more information!
|
87
87
|
|
88
88
|
### License
|
89
89
|
|
data/hirefire-resource.gemspec
CHANGED
data/lib/hirefire/middleware.rb
CHANGED
@@ -33,6 +33,8 @@ module HireFire
|
|
33
33
|
def call(env)
|
34
34
|
@env = env
|
35
35
|
|
36
|
+
handle_queue(env["HTTP_X_REQUEST_START"])
|
37
|
+
|
36
38
|
if test?
|
37
39
|
[ 200, TEST_HEADERS, self ]
|
38
40
|
elsif info?
|
@@ -66,14 +68,17 @@ module HireFire
|
|
66
68
|
#
|
67
69
|
def dynos
|
68
70
|
dyno_data = HireFire::Resource.dynos.inject(String.new) do |json, dyno|
|
69
|
-
json <<
|
71
|
+
json << %(,{"name":"#{dyno[:name]}","quantity":#{dyno[:quantity].call || "null"}})
|
72
|
+
json
|
70
73
|
end
|
71
74
|
|
72
75
|
"[#{dyno_data.sub(",","")}]"
|
73
76
|
end
|
74
77
|
|
75
|
-
|
76
78
|
# Rack PATH_INFO with any RAILS_RELATIVE_URL_ROOT stripped off
|
79
|
+
#
|
80
|
+
# @return [String]
|
81
|
+
#
|
77
82
|
def path
|
78
83
|
if @path_prefix
|
79
84
|
@env["PATH_INFO"].gsub(@path_prefix, "")
|
@@ -97,5 +102,31 @@ module HireFire
|
|
97
102
|
def info?
|
98
103
|
path == "/hirefire/#{@token || "development"}/info"
|
99
104
|
end
|
105
|
+
|
106
|
+
# Writes the Heroku Router queue time to STDOUT if a String was provided.
|
107
|
+
#
|
108
|
+
# @param [String] the timestamp from HTTP_X_REQUEST_START.
|
109
|
+
#
|
110
|
+
def handle_queue(value)
|
111
|
+
log_queue(value) if value
|
112
|
+
end
|
113
|
+
|
114
|
+
# Writes the Heroku Router queue time to STDOUT.
|
115
|
+
#
|
116
|
+
# @param [String] the timestamp from HTTP_X_REQUEST_START.
|
117
|
+
#
|
118
|
+
def log_queue(value)
|
119
|
+
STDOUT.puts("[hirefire:router] queue=#{get_queue(value)}ms")
|
120
|
+
end
|
121
|
+
|
122
|
+
# Calculates the difference, in milliseconds, between the
|
123
|
+
# HTTP_X_REQUEST_START time and the current time.
|
124
|
+
#
|
125
|
+
# @param [String] the timestamp from HTTP_X_REQUEST_START.
|
126
|
+
# @return [Integer] the queue time in milliseconds.
|
127
|
+
#
|
128
|
+
def get_queue(value)
|
129
|
+
(Time.now.to_f * 1000).to_i - value.to_i
|
130
|
+
end
|
100
131
|
end
|
101
132
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hirefire-resource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael van Rooijen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-04 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Load- and schedule-based scaling for web- and worker dynos
|
14
14
|
email: michael@hirefire.io
|
@@ -57,7 +57,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
57
57
|
version: '0'
|
58
58
|
requirements: []
|
59
59
|
rubyforge_project:
|
60
|
-
rubygems_version: 2.6
|
60
|
+
rubygems_version: 2.7.6
|
61
61
|
signing_key:
|
62
62
|
specification_version: 4
|
63
63
|
summary: Autoscaling for your Heroku dynos
|